-
-
Save laser/7664335 to your computer and use it in GitHub Desktop.
ES6 Generators
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
function* powGenerator() { | |
var result = Math.pow(yield "a", yield "b"); | |
return result; | |
} | |
var g = powGenerator(); | |
console.log(g.next().value); // "a", from the first yield | |
console.log(g.next(10).value); // "b", from the second | |
console.log(g.next(2).value); // 100, the result |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment