On Tue, Apr 24, 2018 at 5:58 PM, Augusto Moura <augusto.borg...@gmail.com> wrote: > Assuming `Object.keys` has the same order as a simple `for..in` (as stated > in > mdn)[ https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/keys]. ..
We'll have to fix that page, the spec does not define the order in which `for-in` will enumerate property names. (It does define the order in which `Object.keys` will provide the property names, now, but not `for-in`.) That said, all modern and modern-ish implementations I've tested (to be fair, just V8, SpiderMonkey, Chakra, and IE11's JScript) do indeed follow the defined order with `for-in` as well, with an object's own properties coming before inherited ones - http://jsfiddle.net/arhbn3k2/1/ (IE11-friendly version without Symbols: http://jsfiddle.net/arhbn3k2/5/). (Provided I haven't screwed up that test.) But it's specifically *not* specified - from [EnumerateObjectProperties][1] (the op `for-in` uses to initialize its loop): > The mechanics **and order** of enumerating the properties **is not specified** but must conform to the rules specified below. *(my emphasis)* It says it has to use [[OwnPropertyKeys]] to get the own property keys at each level, but doesn't -- as far as I can tell -- define the sequence of own vs. inherited properties. `Object.entries` follows the order (own properties only): ```js const [first, second, ...rest] = Object.entries(obj); ``` ...but I don't think that, or `keysIterator`, really helps somonek vs. what he's doing now (`Object.keys`). -- T.J. Crowder [1]: https://tc39.github.io/ecma262/#sec-enumerate-object-properties
_______________________________________________ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss