Edwin Reynoso (2016-03-11T14:00:43.000Z)
No need, just replace `this` with the passed parameter:

```javascript
function* keyValIterator (address) { for (let prop in address) { yield [
prop, address[prop] ]; } } var address = { street: '420 Paper St.', city:
'Wilmington', state: 'Delaware' }; for (let [ key, val ] of
keyValIterator(address)) { console.log(key, val); }
```

On Fri, Mar 11, 2016 at 8:55 AM JD Isaacks <jd at jisaacks.com> wrote:

>
> 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
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
>
-- 
Thanks
- Edwin
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20160311/26fb8fca/attachment.html>
eorroe at gmail.com (2016-03-11T14:02:05.719Z)
No need, just replace `this` with the passed parameter:

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

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

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