Created
February 3, 2015 13:55
-
-
Save tdd/73ab0ebc2ea41893361e to your computer and use it in GitHub Desktop.
Partial application
This file contains 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 add(a, b, c) { | |
return a + b + c; | |
} | |
function partial(fx) { | |
var initial = Array.prototype.slice.call(arguments, 1); | |
return function() { | |
var args = Array.prototype.slice.call(arguments); | |
return fx.apply(this, initial.concat(args)); | |
}; | |
} | |
var add22 = partial(add, 2, 20); | |
add22(20); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment