Last active
November 26, 2015 11:59
-
-
Save BenHall/a51d83c178ed0bddcbd9 to your computer and use it in GitHub Desktop.
JavaScript Generator Example
This file contains 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
// 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