For what it's worth, here are the for-in scenarios where I believe a user can
reasonably expect to get identical enumerations from all major browsers
including IE8. The parenthesized items are extrapolations to ES5 features where
I would also expect to not impact the results.
1. For objects that do not inherit any enumerable properties, do not have
any numeric indexed properties, and have no own properties with names that are
the same name as a built-in non-enumerable property of Object.prototype, the
enumeration order is the order in which the properties were added to the
object. For objects created via object literals, object are conceptually added
in the order that they occur within the literal. (For properties added via
Object.create or Object.defineProperties the conceptual addition order is the
enumeration order of the properties of the properties descriptor argument to
those functions.)
a. {z:1, y:2,x:3} //for-in enumeration order: z,y,x
b. var obj={}; obj.a=1; obj.c=2; obj.b=3; //for-in enumeration order:
a,c,b
c. var obj3={z:1, y:2,x:3}; obj3.a=4; obj3.c=5; //for-in enumeration
order: z,y,x,a,c
d. (Object.defineProperties({z:1, y:2,x:3},
{q:{enumerable:true},r:{enumerable:true}}); //for-in enumeration order:
z,y,x,q,r)
2. For objects that do not inherit any enumerable properties and whose
enumerable own properties are numeric indexed properties that are consecutive
integers starting with 0 and all properties were created in a single operation
in ascending numeric order, the enumeration order is ascending numeric order.
a. [0,1,2,3] //enumeration order 0,1,2,3
b. {0:0, 1:1, 2:2} // enumeration order 0,1,2
c. new Array(0,1,2,3) //enumeration order 0,1,2,3
d. (new String("abc") //enumeration order 0,1,2)
e. function(a,b,c){for (var p in arguments);} //enumeration order 0,1,2
In addition, for all major browsers except IE8 and earlier these additional
case is also common
3. For objects that do not inherit any enumerable properties and which do
not have any numeric indexed properties, deleting a property and then adding it
back to the same object moves that property to the end of the enumeration order.
a. var obj1={z:1, y:2,x:3}; delete obj1.y; obj1.y=3.2; //for-in
enumeration order: z,x,y
4. For objects that have inherited enumerable properties but which do not
have any numeric indexed properties (either own or inherited) or any
over-ridden inherited properties the enumerations order is the enumeration of
the own properties of the object, followed by the enumeration of the own
properties of each object on the [[prototype]] chain in [[prototype chain
order]]. The own properties of each prototype object are enumerated using
rules 1 and 2 above. However, if an enumerable property exists at any level of
the prototype chain that has the same name as a property that already been
enumerated at a lower level, that property is not included in the enumeration.
a. var obj3={z:1,x:2}; var obj2=Object.create(obj3);obj2.q=1,obj2.r=2; var
obj1= Object.create(obj2);obj1.a=1,obj1.b=2;// enumeration order a,b,q,r,z,x
In all other cases there is some variation of order or included properties
among major browsers.
> -----Original Message-----
> From: Oliver Hunt [mailto:[email protected]]
> Sent: Friday, May 07, 2010 1:00 PM
> To: stay
> Cc: Allen Wirfs-Brock; Mark S. Miller; [email protected]; es-
> discuss; [email protected]
> Subject: Re: Yet more ambiguities in property enumeration
>
>
> On May 7, 2010, at 12:56 PM, stay wrote:
> > Really? How could sites possibly depend on being able to mark
> > properties non-enumerable but still have them appear in a for-in
> loop?
>
> Sorry, shadowing with a non-enumerable property is new to ES5, I was
> meaning the behaviour i described is what we need to do to ensure sites
> work.
>
> Now days my understanding is the only place where there is confusion
> over behaviour is purely which prototype properties should be
> enumerated.
>
> --Oliver
>
> > --
> > Mike Stay
> > [email protected]
>
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss