Skip to content

Instantly share code, notes, and snippets.

@hg-pyun
Created October 4, 2018 15:32
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hg-pyun/a4f2da306d9f6152efda23b217402444 to your computer and use it in GitHub Desktop.
Save hg-pyun/a4f2da306d9f6152efda23b217402444 to your computer and use it in GitHub Desktop.
iterator.07.js
function* idMaker(){
var index = 0;
while(index < 3)
yield index++;
}
const gen = idMaker();
console.log(gen.next().value); // 0
console.log(gen.next().value); // 1
console.log(gen.next().value); // 2
console.log(gen.next().value); // undefined
// ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment