Member Ordering

Pratap Lakshman (VJ#SDK) pratapl at
Thu Jun 5 09:49:42 PDT 2008

JScript too (starting IE8 Beta1) has an internal representation for arrays that segregates named and numbered properties. The current spec does not mandate an ordering (also, refer section 3.6 from the Deviations document on the wiki), and it appears that various implementations have been able to use that to optimize their internal representations.

For e.g. I see different outputs from the various implementations for the following test case:
Array.prototype.x = "x";
Array.prototype.y = "y";

arr = new Array();
arr[0] = 0;
arr[1] = 1;
arr.exp = "exp";
arr[2] = 2;

arr.x = "shadowX";
arr.y = "shadowY"

for (t in arr) {
  document.write("arr[" + t + "] = " + arr[t] + ", ");

    IE8 B1: arr[0] = 0, arr[1] = 1, arr[exp] = exp, arr[2] = 2, arr[x] = shadowX, arr[y] = shadowY,
      FF 3: arr[0] = 0, arr[1] = 1, arr[exp] = exp, arr[2] = 2, arr[x] = shadowX, arr[y] = shadowY,
Opera 9.02: arr[0] = 0, arr[1] = 1, arr[2] = 2, arr[exp] = exp, arr[x] = shadowX, arr[y] = shadowY,
Safari 3.0: arr[0] = 0, arr[1] = 1, arr[2] = 2, arr[exp] = exp, arr[x] = shadowX, arr[y] = shadowY,

This may not be easy to pin down in the spec.
Perhaps, we should provide other means to mitigate the issues arising out of not having a mandated enumeration order.


-----Original Message-----
From: es3.x-discuss-bounces at [mailto:es3.x-discuss-bounces at] On Behalf Of Lars Hansen
Sent: Wednesday, June 04, 2008 10:53 AM
To: Mark S. Miller; Douglas Crockford
Cc: es3.x-discuss at; es4-discuss at
Subject: RE: Member Ordering

(Bringing back cross-posting to es4-discuss.)

Why should Array objects be treated specially?  I can't
speak to the current internals of Opera, but I know that
in the past it segregated named and numbered properties,
independently of the type of the Object, and enumeration
of properties did not depend on the type of object.  That
seems like a feature.

ES4 'vector' won't behave anything like this.  The current
spec says that the default iterator for vector enumerates
properties in the range 0 .. length-1 in that order and
skips prototype properties and all named properties.
Programmers who want to enumerate those have to create a
custom Enumerator object.

We also believe that the right thing is to provide some
facilities on Array objects so that for-in loops can be
used to iterate across numbered properties only, eg, a
'range' property that delivers a suitable iterator.  But
some details remain unsettled.

It's possible that the uniform thing to do would be for
enumeration to work the same on vector as on Array, and for
there to be a 'range' property on vector to deliver the
sane iterator.  But IMO the Array behavior is broken and
would be changed, were it not for backward compatibility


> -----Original Message-----
> From: Mark S. Miller [mailto:erights at]
> Sent: 4. juni 2008 17:59
> To: Douglas Crockford
> Cc: Lars Hansen; es3.x-discuss at; brendan at
> Subject: Re: Member Ordering
> On Wed, Jun 4, 2008 at 8:42 AM, Douglas Crockford
> <douglas at> wrote:
> > That is indeed discouraging. Perhaps ES3 did the right thing by
> > leaving the order unspecified.
> No. Please specify some deterministic order. I don't much care which.
> But leaving it unspecified complicates testing unnecessarily.
> Also, please see <>
> (draft paper) for further benefits that can only be realized
> after removing such unavoidable sources of hidden
> non-determinism. (Brendan, I've added you to the cc to make
> sure you see this paper. It makes another interesting bridge
> between information-flow and ocaps.)
> A proposal:
> * For direct instances of Array: Use the Opera ordering for
> the own properties. Then the normal prototype-following
> insertion order for ascending the superclass chain. Note that
> Array.prototype is not an instance of Array, and so should
> enumerate by insertion order.
> * For all other objects, even those that fancy themselves to
> be Array-like, Use pure prototype-following insertion order.
> I.e., insertion order of the own properties, then insertion
> order of its prototype, etc...
> Regarding ES4 numerically indexable collections (Vector?) --
> it's up to you guys, but I'd recommend Opera ordering.
> If this proposal isn't good for some reason, reject it. But
> please specify something deterministic!
> --
>     Cheers,
>     --MarkM
Es3.x-discuss mailing list
Es3.x-discuss at

More information about the Es4-discuss mailing list