Created
October 4, 2018 14:58
-
-
Save hg-pyun/b0f664de9ab914e322bd0507f51733cb to your computer and use it in GitHub Desktop.
iterator.03.js
This file contains hidden or 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
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 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment