Created
August 12, 2015 05:13
-
-
Save royling/f35cf6ddddbc8c67644b to your computer and use it in GitHub Desktop.
try out ES2015 Generator - yield vs. yield* (delegation)
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
// `yield*`: yield delegation | |
function* gen1() { | |
yield gen2(); | |
yield* gen2(); | |
yield [3, 4]; | |
yield* [3, 4]; | |
} | |
function* gen2() { | |
yield 1; | |
yield 2; | |
} | |
let iter = gen1(); | |
for (let value of iter) { | |
console.log(value); | |
} | |
// output: | |
// {} | |
// 1 | |
// 2 | |
// [3, 4] | |
// 3 | |
// 4 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment