Default iterator

Jason Orendorff jason.orendorff at
Thu Jun 21 06:07:43 PDT 2012

On Wed, Jun 20, 2012 at 11:37 PM, Erik Arvidsson
<erik.arvidsson at> wrote:
> In our previous discussion I had come to the understanding that the
> default iterator would use a private name. The main benefit for using
> a private name is to not pollute the property name space.

Can you give an example of code that would be harmed by this "pollution"?

It's not pollution to add a useful method to Array.prototype. ES5 added several.

> If this was the ordinary property, "iterator", it might break existing
> code that already use "iterator" in some other way.
> var obj = LibraryX.getObject();
> obj.iterator().forEach(...);

This code won't break.

If anything the new proposal makes it easier to change LibraryX to
support iteration: just add a suitable next() method to its iterator

> It also breaks objects as maps since any string can be used as key.

Again, please give an example of code that would break.

Note that the decision was already made that there would not be an
iterator method on Object.prototype, so objects-as-maps will be
iterated using a helper function:

    var obj = JSON.parse(data);
    import keys, items from '@iter';
    for (let k of keys(obj)) { ... }
    for (let [k, v] of items(obj)) { ... }


More information about the es-discuss mailing list