Created
April 26, 2013 00:02
-
-
Save Coconuthack/5464200 to your computer and use it in GitHub Desktop.
eloquentjs ch 8 bind function
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
//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