I think it would be pretty useful to be able to set an iterator to use in
the context of a for...of statement.

Consider this code:

```javascript

function* keyValIterator () {
  for (let prop in this) {
    yield [ prop, this[prop] ];
  }
}

var address = {
  street: '420 Paper St.',
  city: 'Wilmington',
  state: 'Delaware'
};

for (let [ key, val ] of address using keyValIterator) {
  console.log(key, val);
}

```

This would allow an object to be iterated without needing to assign it's
@@iterator property. It would also allow the same object to be iterated in
different ways for different needs without having to duplicate the object
and assign a different @@iterator for each one.

The example above would only work if the iterator function specified gets
bound to the object being iterated. Not positive if that should be the case
or not. If not bound, it could easily be bound in the `for` statement using
something like `address::keyValIterator`.
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to