实现 call,bind(es6版)

194 阅读1分钟

实现call

Function.prototype.myCall = function (obj, ...args) {
            const newPro = Symbol('newPro')
            obj[newPro] = this
            obj[newPro](...args)
            Reflect.deleteProperty(obj, newPro)
        }

实现bind

Function.prototype.newBind = function (obj) {
            return (...args) => {
                this.call(obj, ...args)
            }
        }