Skip to content

Instantly share code, notes, and snippets.

@bbaaxx
Created November 15, 2017 18:47
Show Gist options
  • Save bbaaxx/45ae9c811d0cc5d547271db764d33f58 to your computer and use it in GitHub Desktop.
Save bbaaxx/45ae9c811d0cc5d547271db764d33f58 to your computer and use it in GitHub Desktop.
Code for blog post about iterators iterables and generators with ES6
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