Skip to content

Instantly share code, notes, and snippets.

@kunigami
Created July 1, 2019 01:00
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/bb11e3868d27791b678c18b395dbe219 to your computer and use it in GitHub Desktop.
Save kunigami/bb11e3868d27791b678c18b395dbe219 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};
},
};
}
it = makeIterator(30);
while (true) {
const {value, done} = it.next();
if (done) {
break;
}
console.log(value);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment