Created
January 8, 2013 21:52
-
-
Save darkone23/4488312 to your computer and use it in GitHub Desktop.
underscore.bind as 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
var add = function(a, b) { | |
return a + b; | |
}; | |
add(20, 30); // 50 | |
// Twenty is so special for our use case that we want it to always be included | |
var addTwenty = _.bind(add, {}, 20); | |
//fn, this, args... | |
addTwenty(30); // 50 | |
// if we wrote this by hand instead: | |
var addTwenty = function(b) { | |
this = {}; | |
var a = 20; | |
return a + b; | |
} | |
addTwenty(30); // 50 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment