Last active
August 29, 2015 14:00
-
-
Save st98/11378840 to your computer and use it in GitHub Desktop.
部分適用?
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
var add = function (x, y) { | |
return x + y; | |
}; | |
var add5 = partial(add, 5); | |
add5(10); // => 15 | |
// 素直に Function#bind を使いましょう | |
var add5 = add.bind(null, 5); | |
add5(10); // => 15 |
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
var partial = (function () { | |
var slice = [].slice; | |
return function (f) { | |
var args = slice.call(arguments, 1); | |
return function () { | |
var fargs = slice.call(arguments); | |
return f.apply(this, args.concat(fargs)); | |
}; | |
}; | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment