Skip to content

Instantly share code, notes, and snippets.

@kunigami
Last active June 16, 2019 06:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kunigami/4250eccdc61b60a876e44a43d8eaaedd to your computer and use it in GitHub Desktop.
Save kunigami/4250eccdc61b60a876e44a43d8eaaedd to your computer and use it in GitHub Desktop.
function makeIterator(n) {
return {
cnt: n,
next: function() {
this.cnt--;
return {value: this.cnt, done: this.cnt < 0};
},
[Symbol.iterator]: function() { return this }
};
}
it = makeIterator(30);
for (value of it) {
console.log(value);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment