Created
January 23, 2014 11:48
-
-
Save hieblmedia/8577294 to your computer and use it in GitHub Desktop.
Function.prototype.bind Polyfill
(Performace optimized: http://grab.by/2ANj)
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
/** | |
* Polyfill for Function.prototype.bind | |
* (bind)[https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Function/bind] | |
* (You don't need to use $.proxy)[http://www.aaron-powell.com/javascript/you-dont-need-jquery-proxy] | |
* Credits: taken from bind_even_never in this discussion: https://prototype.lighthouseapp.com/projects/8886/tickets/215-optimize-bind-bindaseventlistener#ticket-215-9 | |
*/ | |
if (typeof Function.prototype.bind !== "function") { | |
Function.prototype.bind = function(context) { | |
var fn = this, args = Array.prototype.slice.call(arguments, 1); | |
return function(){ | |
return fn.apply(context, Array.prototype.concat.apply(args, arguments)); | |
}; | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment