Skip to content

Instantly share code, notes, and snippets.

@hokaccha
Created March 4, 2010 16:26
Show Gist options
  • Save hokaccha/321855 to your computer and use it in GitHub Desktop.
Save hokaccha/321855 to your computer and use it in GitHub Desktop.
Function.prototype.bind = function(self) {
var f = this;
return function() {
return f.apply(self, Array.prototype.slice.call(arguments));
};
};
// e.g
var obj = {
name: "hokamura",
test: function() {
alert( this.name );
}
};
$("#test").click( obj.test ); //=> undefined
$("#test").click( obj.test.bind(obj) ); //=> hokamura
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment