Skip to content

Instantly share code, notes, and snippets.

@gskachkov
Created June 21, 2017 11:01
Show Gist options
  • Save gskachkov/8c3dfb009954478c9ea09aa5684ed8ef to your computer and use it in GitHub Desktop.
Save gskachkov/8c3dfb009954478c9ea09aa5684ed8ef to your computer and use it in GitHub Desktop.
const objWithIterator = {
[Symbol.iterator]() {
return {
next: function() {
console.log('do next');
return {done: false, value: 'foo'};
},
return: function() {
console.log('do return');
return {done: true, value: 'foo'};
},
throw: function() {
console.log('do throw');
throw new Error('foo');
}
};
}
}
objWithIterator[Symbol.iterator]().next();
// do next
// {done: false, value: "foo"}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment