Skip to content

Instantly share code, notes, and snippets.

@royling
Created August 12, 2015 05:13
Show Gist options
  • Save royling/f35cf6ddddbc8c67644b to your computer and use it in GitHub Desktop.
Save royling/f35cf6ddddbc8c67644b to your computer and use it in GitHub Desktop.
try out ES2015 Generator - yield vs. yield* (delegation)
// `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