Nailing object property order

Tab Atkins Jr. jackalmage at
Thu Apr 16 01:52:00 UTC 2015

On Wed, Apr 15, 2015 at 6:39 PM,  <a.d.bergi at> wrote:
> Hello!
> Why does ES6 specify the order of keys in objects, maps and sets?
> Specifically section 9.1.12 [[OwnPropertyKeys]] says the result list must be "integer indices in ascending numeric, then strings in property creation order, then symbols in property creation order".
> Similarly, Map.prototype.forEach and Set.prototype.forEach use the "original insertion order" of keys for their callbacks, and also their respective @@iterators use the ordered "entries" lists.
> What was the motivation to pin these down in ES6?

Because, for objects at least, all implementations used approximately
the same order (matching the current spec), and lots of code was
inadvertently written that depended on that ordering, and would break
if you enumerated it in a different order.  Since browsers have to
implement this particular ordering to be web-compatible, it was
specced as a requirement.

There was some discussion about breaking from this in Maps/Sets, but
doing so would require us to specify an order that is *impossible* for
code to depend on; in other words, we'd have to mandate that the
ordering be *random*, not just unspecified.  This was deemed too much
effort, and creation-order is reasonable valuable (see OrderedDict in
Python, for example), so it was decided to have Maps and Sets match


More information about the es-discuss mailing list