Function.prototype.myBind = function (thisArg, ...args) {
if (typeof this !== 'function') {
throw new Error ('Not a function!')
}
const _this = this
const fnBound = function (...args1) {
const self = this instanceof _this ? this : thisArg
_this.apply(self, args.concat(args1))
}
fnBound.prototype = Object.create(_this.prototype)
return fnBound
}
JS 手写bind
最新推荐文章于 2023-05-10 17:11:21 发布