Skip to content

Instantly share code, notes, and snippets.

@hg-pyun
Created October 4, 2018 15:32
Show Gist options
  • 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.

Revisions

  1. hg-pyun created this gist Oct 4, 2018.
    13 changes: 13 additions & 0 deletions iterator.07.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,13 @@
    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
    // ...