Created
November 15, 2017 18:47
-
-
Save bbaaxx/45ae9c811d0cc5d547271db764d33f58 to your computer and use it in GitHub Desktop.
Code for blog post about iterators iterables and generators with ES6
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const otherObject = { | |
a: 'juan', | |
b: 'tu', | |
c: 'tri' | |
} | |
function* objectIterator(obj) { | |
for (let prop of Object.keys(obj)) { | |
yield obj[prop]; | |
} | |
}; | |
const iter = objectIterator(otherObject) | |
console.log(iter.next().value); // juan | |
console.log(iter.next().done); // false | |
console.log(iter.next().value); // tri | |
console.log(iter.next().done); // true |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment