一、手动实现call方法
Function.prototype.call2=function(object){
let obj =object;
obj.fn = this;
let result;
let args = [...argements].splice(1);
return result =obj.fn(...args)
}
二、重写apply方法
Function.prototype.call2=function(object){
let obj =object;
obj.fn = this;
let result;
let args = [...argements].splice(1);
return result =obj.bn(args)
}
三、手动实现bind方法
Function.prototype.myBind = function(obj,...arg1){ //arg1收集剩余参数
return function (...arg2) { //返回箭头函数, this绑定调用这个方法(myFind)的函数对象
return this.Apply( obj, arg1.concat(arg2) ); // 将参数合并
}
}