Skip to content

Instantly share code, notes, and snippets.

@hieblmedia
Created January 23, 2014 11:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hieblmedia/8577294 to your computer and use it in GitHub Desktop.
Save hieblmedia/8577294 to your computer and use it in GitHub Desktop.
Function.prototype.bind Polyfill (Performace optimized: http://grab.by/2ANj)
/**
* 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