Skip to content

Instantly share code, notes, and snippets.

@hg-pyun
Created October 4, 2018 14:58
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/b0f664de9ab914e322bd0507f51733cb to your computer and use it in GitHub Desktop.
Save hg-pyun/b0f664de9ab914e322bd0507f51733cb to your computer and use it in GitHub Desktop.
iterator.03.js
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