Skip to content

Instantly share code, notes, and snippets.

@morganrallen
Created August 19, 2013 21:00
Show Gist options
  • Save morganrallen/6274144 to your computer and use it in GitHub Desktop.
Save morganrallen/6274144 to your computer and use it in GitHub Desktop.
Create repeating function. Takes arguments from first call and repeat on each call there after.
function repeater(fn) {
var args = false;
return function() {
if(args === false) args = arguments;
return fn.apply(this, args);
}
};
function add(a, b) {
return a + b;
};
var r = repeater(add);
console.log(r(1,2));
console.log(r(2,2));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment