Skip to content

Instantly share code, notes, and snippets.

@hg-pyun
Created October 4, 2018 14:58
Show Gist options
  • Save hg-pyun/b0f664de9ab914e322bd0507f51733cb to your computer and use it in GitHub Desktop.
Save hg-pyun/b0f664de9ab914e322bd0507f51733cb to your computer and use it in GitHub Desktop.

Revisions

  1. hg-pyun revised this gist Oct 4, 2018. 1 changed file with 2 additions and 5 deletions.
    7 changes: 2 additions & 5 deletions iterator.03.js
    Original file line number Diff line number Diff line change
    @@ -13,8 +13,5 @@ const iterable = {
    };

    for (var value of iterable) {
    console.log(value);
    }
    // 0
    // 1
    // 2
    console.log(value); // 0 1 2
    }
  2. hg-pyun created this gist Oct 4, 2018.
    20 changes: 20 additions & 0 deletions iterator.03.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,20 @@
    const iterable = {
    [Symbol.iterator]() {
    return {
    i: 0,
    next() {
    if (this.i < 3) {
    return { value: this.i++, done: false };
    }
    return { value: undefined, done: true };
    }
    };
    }
    };

    for (var value of iterable) {
    console.log(value);
    }
    // 0
    // 1
    // 2