Skip to content

Instantly share code, notes, and snippets.

@BenHall
Last active November 26, 2015 11:59
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 BenHall/a51d83c178ed0bddcbd9 to your computer and use it in GitHub Desktop.
Save BenHall/a51d83c178ed0bddcbd9 to your computer and use it in GitHub Desktop.
JavaScript Generator Example
// Example from https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Iterators_and_Generators
function* idMaker(){
var index = 0;
while(true)
yield index++;
}
var gen = idMaker();
console.log(gen.next().value);
console.log(gen.next().value);
console.log(gen.next().value);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment