foliojs/restructure

JavaScript object order not guaranteed

mattieb opened this issue · 1 comments

Hi, thanks for making restructure!

It looks great for our needs, but I have one small concern: Struct takes an object, and according to the spec, object iteration order is not guaranteed.

I assume nobody has run into this problem yet because implementations do in fact guarantee order.

Any suggestions for working around this? Would you be interested in a patch to make it possible to supply Struct with an array of key/value pairs instead?

Old spec (<=ES5) - clearly indefinite (cuz they didn't want to say). New spec (ES6,ES2015) - mostly clarified (a bit more than "just saying...") - use insertion order or as the spec says "property creation order".

See Axel's article See also the ES2015 spec section 9.1.11

Key is [[OwnPropertyKeys]] now says "property creation order", and many other ext/int APIs depend on it. The 'caveat' is that numeric keys and Symbols are handled differently....

The real point is that the weight on the standards committee was to codify according to actual practice, which itself was under pressure from the mass of code that depended on "the way it was always done - insertion order". For ES5 they didn't 'cave'. For ES2015 they gave up the pretense that practice didn't dictate language specifications. The language bent to the masses! (yay?) Ignore that cited SO answer as the world has moved onward.
String object keys will be returned in insertion order