Skip to content

Instantly share code, notes, and snippets.

@bmeck
Last active September 14, 2016 08:59
Show Gist options
  • Save bmeck/12e979837b9a73b5f377 to your computer and use it in GitHub Desktop.
Save bmeck/12e979837b9a73b5f377 to your computer and use it in GitHub Desktop.
how a counter generator in es6 maps to a function in es5
function* counter() {
var count = 0;
while (true) {
yield count++;
}
}
function counter() {
var done = false;
var count = 0;
return {
next: function (value) {
if (done) throw new Error('Generator is done');
return {done: done, value: count++};
},
throw: function (err) {
done = true;
throw err;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment