Skip to content

Instantly share code, notes, and snippets.

@watilde
Created May 14, 2013 00:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save watilde/5572624 to your computer and use it in GitHub Desktop.
Save watilde/5572624 to your computer and use it in GitHub Desktop.
yield
function simpleGenerator(){
yield "first";
yield "second";
yield "third";
for (var i = 0; i < 3; i++)
yield i;
}
var g = simpleGenerator();
console.log(g.next()); // "first"
console.log(g.next()); // "second"
console.log(g.next()); // "third"
console.log(g.next()); // 0
console.log(g.next()); // 1
console.log(g.next()); // 2
console.log(g.next()); // StopIteration
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment