call
Function.prototype.mycall = function(content){
if(typeof(this) !== "function"){
throw new Error('not a function')
}
content = content || window;//当参数为空时,视为指向window
content.fn=this;
let args = [...arguments].splice(1);
let result = content.fn([...args]);
delete content.fn
return result;
}
apply
Function.prototype.myapply = function(content){
if(typeof(this) !== "function"){
throw new Error('not a function')
}
content = content || window;
content.fn = this;
let result;
if(arguments[1]){
result = content.fn(...arguments[1])
}else{
result = content.fn()
}
delete content.fn;
return result;
}