Set iterators

Michael A. Smith michael at smith-li.com
Mon Feb 13 21:24:50 PST 2012


On Mon, Feb 13, 2012 at 11:59 PM, Allen Wirfs-Brock
<allen at wirfs-brock.com> wrote:
>
> I would normally agree with you.  ECMAScript for-in property enumeration order is defined in exactly that manner.  However, the experience with JavaScript in browsers is that there is a significant amount of code that has been developed that depends upon a particular enumeration order that is widely used in browsers.  People write code with dependencies (often unintentional) upon the enumeration order used by their favorite browser.  If their code breaks when it is run on other browsers, they complain.  Over time, this is a force that push browsers with less market share to match the implementation decisions of browser with more market share.  This happened with for-in enumeration and I expect it will happen with Set/Map iteration order if we leave it unspecified.

Browsers are not the only target here. Are you saying you expect this
behavior from non-browser implementations as well? Even if you do, I
am not very convinced this is a solid reason to specify ordering at
the implementation level for a data type that does not fundamentally
imply an ordering.

But hypothetically let's say we do want to go with insertion-order. In
that case, what happens to the order when you attempt to insert an
element that already exists in the set?

OrderedSet('a', 'b', 'c').insert('b')

Is that OrderedSet('a', 'b', 'c') or is it OrderedSet('a', 'c', 'b')?

-Michael A. Smith


More information about the es-discuss mailing list