Skip to content

Instantly share code, notes, and snippets.

@apburnes
Created November 20, 2013 21:34
Show Gist options
  • Save apburnes/7571492 to your computer and use it in GitHub Desktop.
Save apburnes/7571492 to your computer and use it in GitHub Desktop.
JS Partials
var __slice = Array.prototype.slice;
function callFirst(fn, larg) {
return function() {
var args = __slice.call(arguments, 0);
return fn.apply(this, [larg].concat(args));
}
}
function callLast(fn, rarg) {
return function() {
var args = __slice.call(arguments, 0);
return fn.apply(this, args.concat([rarg]))
}
}
function greet(me, you) {
return "Hello " + you + ", this is " + me;
}
var sayHelloTo = callFirst(greet, 'Andrew');
var beGreetedBy = callLast(greet, 'Andrew');
sayHelloTo('John')
beGreetedBy('Terry')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment