iteration order for Object

Wes Garland wes at
Fri Mar 11 07:35:39 PST 2011

On Fri, Mar 11, 2011 at 10:07 AM, Claus Reinke <claus.reinke at>wrote:

> I believe it is very very important that the ECMAScript standard specify
>> that when a new Object is created, iteration traverses properties in
>> the order they are added, regardless of whether the properties are numeric
>> or not.
> Some users might prefer 'in the order of keys'. That is predictable,
> and allows for efficient implementation (both sparse and dense).

Are you suggesting changing the enumeration order which is currently
implemented as "iteration order matches insertion order" under the careful
set of conditions Allen enumerated earlier in this thread?  (e.g. no
enumerable props on prototype).

If so - the thought of this makes me pretty nervous.  There is undoubtedly
significant amounts of code in the wild on the web which depend on the
current enumeration order, and changing this would increase the size of the
harmony-uptake tax (code audits and refactors).

Someone -- Mark Miller? -- suggested an interesting option when this
discussion came up last on this list (around Christmas 2010 IIRC).
Basically -- enumerate named props in insertion order, and numeric props in
numeric.   This gets pretty close to what most developers seem to expect,
while leaving the door wide open for fast implementation of array-like

> Most of these are just awkward ways of saying "this
> is the order I want" and "I also want hashmap access". So why not write
> that out explicitly, with an optional ordering parameter, making the
> enumeration explicit
> when the default ordering isn't suitable:

You know, most of the time when I see valid use-cases for an alternate
enumeration order, I can't help but think to myself: this might have a
better solution if ES had generators, something like what Mozilla prototyped
in JavaScript 1.7, and you could make such a generator the enumeration hook
for the object in question.


Wesley W. Garland
Director, Product Development
PageMail, Inc.
+1 613 542 2787 x 102
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the es-discuss mailing list