iteration order for Object
charles at isomorphic.com
Fri Mar 11 07:48:04 PST 2011
On 3/11/2011 7:35 AM, Wes Garland wrote:
> Someone -- Mark Miller? -- suggested an interesting option when this discussion came up last on
> this list (around Christmas 2010 IIRC). Basically -- enumerate named props in insertion order,
> and numeric props in numeric. This gets pretty close to what most developers seem to expect,
> while leaving the door wide open for fast implementation of array-like objects.
Just connecting the dots - I addressed this in my first email on the subject. While it
superficially sounds like a good compromise, I actually think it's the worst possibility: it
requires browser vendors to implement limited order preservation, preventing deeper
optimizations like sorted keys. At the same time, it requires that applications and frameworks
deal with lack of order for numeric keys, which are very common: in the use case of mapping
stored to displayed values, stored values are very often numeric.
I also think that it's surprising and counter-intuitive that numeric keys are treated
differently from non-numeric. The reality is that an implementation detail of Array is
bleeding through to Object.
More information about the es-discuss