Ordering of JS properties

Harri Porten porten at froglogic.com
Mon Feb 16 23:23:33 CET 2004


Hi!

we have two interesting (duplicated) bug reports on bugs.kde.org:

  http://bugs.kde.org/28474
  http://bugs.kde.org/62928

They are about ordering of object properties. Since the original,
primitive property implementation has been replaced by a faster map we
don't maintain the order of added properties. This is according to the
spec which says the order of undefined.

Still, other browsers do it differently which is usually a source of
trouble in real world web sites. Running the following example

var a = { x: 0 };
a.w = 1;
a.y = 2;

var s = "";
for (var i in a)
   s += a[i];
document.write(s);

in Mozilla gives "012" for example.

Is this issue worth fixing? The only solution - other than returning to
the slow list - is to do double book keeping with an index or list which
will cause an additional memory overhead. Are there containers with the
property of fast lookups while still supporting iteration in the order of
addition ? :)

Harri.



More information about the Khtml-devel mailing list