Skip to content

Instantly share code, notes, and snippets.

@Floofies
Last active November 12, 2018 20:14
Show Gist options
  • Save Floofies/5dc7f1d47c9a08b0cdb2991fd752c149 to your computer and use it in GitHub Desktop.
Save Floofies/5dc7f1d47c9a08b0cdb2991fd752c149 to your computer and use it in GitHub Desktop.
Generator/iterator
function generator() {
var loc = 0;
const state = { done: false, value: undefined };
const iterator = {
next: function() {
switch(loc) {
case 0:
console.log("Hello World");
loc++;
break;
case 1:
console.log("Goodbye MoonMan");
loc++;
break;
case 2:
console.log("What's up, doc?");
state.done = true;
loc++;
}
return state;
}
};
return iterator;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment