Skip to content

Instantly share code, notes, and snippets.

@yosriady
Created April 11, 2014 14:35
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 yosriady/10473905 to your computer and use it in GitHub Desktop.
Save yosriady/10473905 to your computer and use it in GitHub Desktop.
Javascript Yield example
function yfunc(prev, index, array, callback){
var newValue = callback(prev, index, array);
console.log(newValue);
return function(){
return yfunc(newValue, index++, array.push(newValue), callback)
};
}
function yield(callback){
return yfunc(null, 0, [], callback);
}
var oddEnum = yield(function(prev, index, array){
return 2*index + 1;
});
oddEnum() // 1,3,4,7,9
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment