Created
May 20, 2016 04:22
-
-
Save ericelliott/4429bd470b8a6e85e43a88ff3869bbd0 to your computer and use it in GitHub Desktop.
Simple generator example
This file contains 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
function* foo() { | |
yield 'a'; | |
yield 'b'; | |
yield 'c'; | |
} | |
for (const val of foo()) { | |
console.log(val); | |
} | |
// a | |
// b | |
// c | |
const [...values] = foo(); | |
console.log(values); // ['a','b','c'] |
Because of yield and * generator syntax
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello! Sorry for commenting here...I have a question:
Why there's no
next()
but you can still iterate it in thefor
loop?