Created
June 2, 2010 18:41
-
-
Save NV/422789 to your computer and use it in GitHub Desktop.
Better function.bind()
This file contains hidden or 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
| // 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} |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Whoops. Thanks!