brendan at mozilla.org
Tue Jun 3 11:56:33 PDT 2008
On Jun 3, 2008, at 9:25 AM, Douglas Crockford wrote:
> ES3 says that objects are unordered with respect to the sequence
> produced by
> for...in. Nevertheless, many web developers have an expectation
> that the
> sequence should reproduce the insertion order. That implied order
> is strictly
> complied with in all browsers except Opera which can optimize
> numeric sequences.
> We like the Opera optimization. Web developers don't seem to notice
> that it
> diverges from common practice, except that for in on arrays seems
> to work
> correctly in cases that seem to be confused on other browsers.
Confused in other browsers *only* if one creates the array's indexed
properties in other than index order. That's rare, so it's not a huge
hardship and I hope we can do what you propose, even though it's an
incompatible change from past releases of most browsers. From a
js> a = 
js> for(i in a)print(i)
> We are also reluctant to slap Opera for having produced the best
> of this feature in a way that fully complies with the current
js> a = 
js> for(i in a) print(i)
but only for dense arrays: length <= 32 or load factor >= .25 -- and
no ad-hoc named, direct properties. I hear Opera has similar
restrictions, but I haven't tested.
There are other hard cases:
js> a = 
js> Array.prototype = 1
js> Object.prototype = 0
js> for (i in a) print(i)
> We want to better specify the ordering of for...in because the
> community has expectations. We are reluctant to impose a particular
> implementation of objects, but we do like that Opera's optimization
> seems to
> best match expectations in a way that is the least surprising, and
> possibly the
> best performing.
> How would the other three feel about having to adopt Opera's
We need an exact spec of what Opera does to agree, or better: we need
a spec that matches Opera and Firefox 3 for the easy case of dense
arrays with no prototype indexed properties and no ad-hoc named
I'm in favor of for-in using index order for arrays, provided we can
get the hard cases "right" for some reasonable definition of "right".
We'd adapt future Mozilla releases to match.
More information about the Es4-discuss