- 首先你得知道call是什么
- call能够改变它的调用者的this指向 第一个参数就是想要改变的this 指向, 接下去是一个一个的参数,
- 上图举例子

可以看到console.log出来的 均是我们想要的结果
注意
如果没有改变this 指向 因为相当于立即执行函数,所以this会指向window
开始今天的主题
纯净版代码
Function.prototype.mycall=function(){
console.log(arguments);
const args= Array.from(arguments)
const t = args.shift()
const temp=this
console.log(temp);
t.fn=temp
console.log(t.fn);
console.log(t);
t.fn(...args)
delete t.fn
}
function fn(a,b){
console.log('a',a);
console.log('b',b);
console.log('this',this);
}
fn.mycall({x:10},10,20)
Function.prototype.mycall=function(){
console.log(arguments);
const args= Array.from(arguments)
const t = args.shift()
const temp=this
console.log(temp);
t.fn=temp
console.log(t.fn);
console.log(t);
t.fn(...args)
delete t.fn
}
function fn(a,b){
console.log('a',a);
console.log('b',b);
console.log('this',this);
}
fn.mycall({x:10},10,20)