手写call bind apply
2021-07-12 本文已影响0人
姜酱i
手写call bind apply
Function.prototype.myCall = function(o,...args){
let content = (o===null||o===undefined)?window:o
content._fun = this
let result = content._fun(args)
delete content._fun
return result
}
Function.prototype.myBind = function(o){
let content = (o===null||o===undefined)?window:o
content._fun = this
return function(...args){
content._fun(args)
delete content._fun
}()
}
Function.prototype.myApply = function(o,args){
let content = (o===null||o===undefined)?window:o
content._fun = this
let result = content._fun(...args)
delete content._fun
return result
}