Skip to content

Instantly share code, notes, and snippets.

@darkone23
Created January 8, 2013 21:52
Show Gist options
  • Save darkone23/4488312 to your computer and use it in GitHub Desktop.
Save darkone23/4488312 to your computer and use it in GitHub Desktop.
underscore.bind as partial application
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