Created
April 26, 2014 00:11
-
-
Save subtubes-io/11307690 to your computer and use it in GitHub Desktop.
Method binding mixing pattern using JavaScript with 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 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