Skip to content

Instantly share code, notes, and snippets.

@subtubes-io
Created April 26, 2014 00:11
Show Gist options
  • Save subtubes-io/11307690 to your computer and use it in GitHub Desktop.
Save subtubes-io/11307690 to your computer and use it in GitHub Desktop.
Method binding mixing pattern using JavaScript with partial application
var methodMixin = function (func, obj){
var args = Array.prototype.slice.apply(arguments, [2]);
return function () {
func.apply(obj, args);
}
};
var sample = {name: "larry"};
var f = function (salute) {
console.log(salute + " " + this.name);
};
var my = methodMixin(f, sample, "hi");
my();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment