Subj : Re: for/in loops To : Alex Fritze From : Brendan Eich Date : Tue May 11 2004 05:43 pm Alex Fritze wrote: > Hi, > > A couple of questions about for/in: > > 1. > Getters & setters defined with __defineGetter__/__defineSetter__ are > currently not enumerated in for/in loops. Is there a reason for that? Looks like a bug to me, especially in light of the prior getter= / setter= operators implemented by yours truly, on which __dG__ and __dS__ were based. getter= and setter= were deprecated due to JS2 / ECMA-262 Edition 4 forward compatibility concerns. I'll fix in the 1.8a trunk. > 2. > The code > function f() { var x,y,z; } > f.foo = "bar"; > for(var p in f) dump(p); > yields > xyzfoo > > Why are f's private variables enumerated? Compatibility with the pre-ECMA Netscape JS implementations. We could ditch this, but I'm not sure I wouldn't break something I care about. Does this break you? ECMA allows extensions, although extending function objects with properties such as these makes for trouble. See http://lxr.mozilla.org/mozilla/source/js/src/jsinterp.c#443 and surrounding. /be .