iteration order for Object

Lasse Reichstein reichsteinatwork at
Mon Mar 14 03:09:06 PDT 2011

On Fri, 11 Mar 2011 16:48:04 +0100, Charles Kendrick  
<charles at> wrote:

> Just connecting the dots - I addressed this in my first email on the  
> subject.  While it superficially sounds like a good compromise, I  
> actually think it's the worst possibility: it requires browser vendors  
> to implement limited order preservation, preventing deeper optimizations  
> like sorted keys.

Implementors already have to do that. In V8, some objects have their
properties backed by a hashmap. This just means that it needs an extra  
in that hashmap (a 50% increase in size) to store the insertion index, and  
extract and sort the keys by insertion index before iterating over them.

That also means that some ideas that might work well in one implementation,
   function hasKey(object) { for(var _ in object) return true; return  
false; }
(which I believe works quickly in SpiderMonkey) will work much worse in  
implementations - by at least a factor of 10.

So yes, (some) objects are hashmaps ... plus some more.

/L 'firmly in the "they are not ordered and never were, damnit!" camp'
Lasse Reichstein - reichsteinatwork at

More information about the es-discuss mailing list