Created
August 19, 2013 21:00
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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