Last active
August 6, 2020 03:56
-
-
Save MarvinXu/c1b6c76c4b3ebfa66b01ab833ab44d4c to your computer and use it in GitHub Desktop.
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 (thisArg) { | |
var fn = aFunction(this), | |
slice = [].slice, | |
partArgs = slice.call(arguments, 1), | |
boundF | |
boundF = function () { | |
var args = partArgs.concat(slice.call(arguments)) | |
var arr = [] | |
for (var i = 0; i < args.length; i++) { | |
arr.push('a[' + i + ']') | |
} | |
return this instanceof boundF | |
? Function('C,a', 'return new C(' + arr + ')')(fn, args) | |
: fn.apply(thisArg, args) | |
} | |
return boundF | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment