SOURCE

let name = 'WIN'
function person(a,b,c,d){
    return{
        name:this.name,
        a:a,b:b,c:c,d:d
    }
    // console.log(this.name)
    // console.log(`爱好:${a}、${b}、${c}、${d}`)
}

let p1 = {name:'Kevin'};

// person.call(p1,'摄影','尤克里里','模型','旅游')
Function.prototype.newCall = function(obj,...args){
    // 此时的this指向person方法,
    // 把方法赋值到对象,执行然后删除
    var obj = obj || window
    obj.fn = this; 
    const result = obj.fn(...args);
    delete obj.fn;
    return result
}
// 完成call
// let b1 = person.newCall(p1,'摄影','尤克里里','模型','旅游');
// console.log(JSON.stringify(b1))

// person.apply(p1,['摄影','尤克里里','模型','旅游'])
Function.prototype.newApply = function(obj,arr){
    var obj = obj || window
    obj.fn = this
    const result = obj.fn(...arr);
    delete obj.fn
    return result
}
// 完成apply
// let b2 = person.newApply(p1,['摄影','尤克里里','模型','旅游']);
// console.log(JSON.stringify(b2))
console 命令行工具 X clear

                    
>
console