编辑代码

// call
// 严格模式下,不指定第一个参数,this指是undefined
// 非严格模式下,指定null或undefined时指向全局对象,原始对象值
// 会被包装

Function.prototype.myCall = function (context, ...args) {
    context = context || window
    context.fn = this
    const res = context.fn(...args)
    delete context.fn
    return res
}

// apply

Function.prototype.myApply = function (context, args) {
    context = context || window
    context.fn = this
    console.log('args', args)
    const res = context.fn(...args)
    delete context.fn
    return res
}