Skip to content

Instantly share code, notes, and snippets.

@NV
Created June 2, 2010 18:41
Show Gist options
  • Select an option

  • Save NV/422789 to your computer and use it in GitHub Desktop.

Select an option

Save NV/422789 to your computer and use it in GitHub Desktop.
Better function.bind()
// Better function.bind()
// Origin http://twitpic.com/1tbwip
// Inspired by http://perfectionkills.com/semantic-constructors/
Function.prototype.bind = function bind(thisObject) {
var func = this;
var args = Array.prototype.slice.call(arguments, 1);
function bound() {
return func.apply(thisObject, args.concat(Array.prototype.slice.call(arguments, 0)));
}
bound.toString = function toString() {
return func.toString();
};
return bound;
}
function foo(){return 1}
foo.bind({}).toString() //function foo(){return 1}
@NV

NV commented Jun 2, 2010

Copy link
Copy Markdown
Author

Whoops. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment