Skip to content

Instantly share code, notes, and snippets.

@Coconuthack
Created April 26, 2013 00:02
Show Gist options
  • Save Coconuthack/5464200 to your computer and use it in GitHub Desktop.
Save Coconuthack/5464200 to your computer and use it in GitHub Desktop.
eloquentjs ch 8 bind function
//Bind an inner function to this, same this as outer function
//EloquentJS Ch8
function bind(func, object) {
return function(){
return func.apply(object, arguments);
};
}
//Example
var testArray = [];
var pushTest = bind(testArray.push, testArray);
pushTest("A");
pushTest("B");
show(testArray); //-> ["A", "B"]
function method(name, object) {
return function(){
return object[name].apply(object, arguments);
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment