Created
January 24, 2011 04:38
-
-
Save shinypb/792841 to your computer and use it in GitHub Desktop.
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: function(that, func) { | |
if(typeof(func) !== 'function') { | |
// Only functions can be bound, but for readability of calling code, we | |
// don't want to worry about calling bind on non-functions. | |
return func; | |
} | |
if(func.bind) { | |
// Use built-in implementation of bind | |
return func.bind(that); | |
} | |
return function() { | |
return func.apply(that, arguments); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment