Skip to content

Instantly share code, notes, and snippets.

@dclowd9901
Created March 5, 2015 18:07
Show Gist options
  • Save dclowd9901/12f537692156b7799c0f to your computer and use it in GitHub Desktop.
Save dclowd9901/12f537692156b7799c0f to your computer and use it in GitHub Desktop.
Generators without generators
function generator(func) {
var statefulArg;
return function() {
statefulArg = statefulArg || arguments[0];
statefulArg = func.apply(this, [statefulArg]);
return statefulArg
};
}
function double(numberToDouble) {
return numberToDouble * 2;
}
generatorDouble = generator(double);
generatorDouble(1); // 2
generatorDouble(); // 4
generatorDouble(); // 8
@dclowd9901
Copy link
Author

Actually is iterator :\

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment