call内部实现
Function.prototype.call = function(context){
context.fn = this
let args = [...arguments].slice(1)
let res = context.fn(...args)
delete context.fn
return res
}
apply内部实现
Function.prototype.apply= function(context){
context.fn = this
let args = arguments[1]
let res = context.fn(...args)
delete context.fn
return res
}
bind内部实现
Function.prototype.myBind= function(context){
context.fn = this
let args = [...arguments].slice(1)
return function(){
let newArgs = args.concat([...arguments])
let res = context.fn(...newArgs)
delete context.fn
return res
}
}