Skip to content

Instantly share code, notes, and snippets.

@psiborg
Created January 6, 2012 08:15
Show Gist options
  • Save psiborg/1569640 to your computer and use it in GitHub Desktop.
Save psiborg/1569640 to your computer and use it in GitHub Desktop.
JS Context Bind 2
var myObject = {
someProperty: 42
};
myObject.method = function () {
console.log(this.someProperty);
};
function bindContext (func, context) {
return function () {
return func.apply(context, arguments);
};
}
var boundMethod = bindContext(myObject.method, myObject);
boundMethod(); // 42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment