Skip to content

Instantly share code, notes, and snippets.

@MarvinXu
Last active August 6, 2020 03:56
Show Gist options
  • Save MarvinXu/c1b6c76c4b3ebfa66b01ab833ab44d4c to your computer and use it in GitHub Desktop.
Save MarvinXu/c1b6c76c4b3ebfa66b01ab833ab44d4c to your computer and use it in GitHub Desktop.
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