实现了一下call和apply, 贴出来大家评评,没实现参数校验,只适合正常调用的场景
call
Function.prototype.myCall = function (){
const args = Array.prototype.slice.call(arguments)
const thisObj = args[0];
Object.prototype.runOuterMethod = this;
args.splice(0,1);
thisObj.runOuterMethod(...args);
delete Object.prototype.runOuterMethod
}
apply
Function.prototype.myApply = function (thisObj, args){
Object.prototype.runOuterMethod = this;
thisObj.runOuterMethod(...args);
delete Object.prototype.runOuterMethod
}