iteration order for Object
charles at isomorphic.com
Sat Mar 12 11:27:14 PST 2011
On Mar 12, 2011, at 10:41 AM, Brendan Eich <brendan at mozilla.com> wrote:
> On Mar 12, 2011, at 9:54 AM, David Bruant wrote:
>> The little "issue" I see in returning 1) index properties in ascending
>> order 2) all other properties in addition order is that there is a bit
>> of information lost in the process: overall property addition order
>> (index properties included).
> This is an issue in theory. Beware _a priori_ reasoning about usability issues.
> In practice both users and (especially) implementors Do Not Want indexed properties enumerated in insertion order. The proof is the use of for-in over arrays, still common enough, also advised against (but that is like talking back to the tide).
I don't understand why this is still being discussed as a single behavior across Array and Object.
If we define the iteration order as:
1. Object: in-order including indices
2. Array: indices first
1. There's no information loss going from Object literal to live Object
2. Array has the for..in behavior people expect
3. Object has a useful behavior (similar to Java LinkedHashMap) instead of a surprising behavior (treating indices specially)
This is aside from the performance and backcompat benefits covered previously.
You mentioned JS conflates Arrays and Objects - so - let's stop doing that :)
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the es-discuss