Created
July 31, 2011 17:33
-
-
Save xulapp/1116996 to your computer and use it in GitHub Desktop.
bind ES3
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
Function.prototype.bind = Function.prototype.bind || function bind(thisArg) { | |
var method = this; | |
var args = Array.prototype.slice.call(arguments, 1); | |
return function bound() { | |
var _args = args.concat(Array.prototype.slice.call(arguments)); | |
if (!(this instanceof bound)) | |
return method.apply(thisArg, _args); | |
var __args = []; | |
for (var i = 0, len = _args.length; i < len; i++) | |
__args.push('_args[' + i + ']'); | |
return eval('new method(' + __args.join(',') + ')'); | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
nice one