On Wed, Apr 15, 2015 at 6:39 PM, <[email protected]> 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, 23.1.3.5 Map.prototype.forEach and 23.2.3.6 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 Objects. ~TJ _______________________________________________ es-discuss mailing list [email protected] https://mail.mozilla.org/listinfo/es-discuss

