Skip to content

Instantly share code, notes, and snippets.

@egermano
Created August 31, 2012 15:58
Show Gist options
  • Save egermano/3555023 to your computer and use it in GitHub Desktop.
Save egermano/3555023 to your computer and use it in GitHub Desktop.
bind to change the function scope
// bind to change the function scope and send arguments for the functions
Function.prototype.bind = function(context) {
var __method = this,
args = Array.prototype.slice.call(arguments, 1);
return function() {
var a = Array.prototype.concat(Array.prototype.slice.call(arguments), args);
return __method.apply(context, Array.prototype.slice.call(a));
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment