-
-
Save andrewkowalik/5848106 to your computer and use it in GitHub Desktop.
bind examples
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
function bind(func, object) { | |
return function () { | |
return func.apply(object, arguments); | |
}; | |
} | |
Function.prototype.myBind = function (context) { | |
var that = this; | |
return function () { | |
return that.apply(context, arguments); | |
} | |
} | |
var testArray = []; | |
var testArray2 = []; | |
//Using function | |
// var pushTest = bind( testArray.push, testArray); | |
//monkey-patching | |
var pushTest = testArray.push.myBind(testArray2); | |
pushTest("A"); | |
pushTest("B"); | |
console.log(testArray); | |
console.log(testArray2); |
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
adsfasdf |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment