Subj : Re: for/in loops To : netscape.public.mozilla.jseng From : Alex Fritze Date : Wed May 12 2004 03:12 pm Brendan Eich wrote: > 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. > I see the fix is already on the trunk. That was quick. Thanks! > >> 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? No, it doesn't really break me, it just struck me as odd. I'm wanting to store meta information about a function (e.g. a help string) as function properties. I guess, while it might cause some jumping through hoops in SetFunctionSlot(), that is ok by ECMA and Spidermonkey and not asking for trouble, right? > 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. Thanks for pointing me to that comment. I think I understand now how args & vars end up as properties, although I still don't get how enumerating them is useful - especially now that they are distinct from function properties from a user perspective. Regards Alex .