Created
June 21, 2017 11:01
-
-
Save gskachkov/8c3dfb009954478c9ea09aa5684ed8ef to your computer and use it in GitHub Desktop.
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 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