美文网首页
手写call bind apply

手写call bind apply

作者: 姜酱i | 来源:发表于2021-07-12 15:50 被阅读0次

手写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
}

相关文章

网友评论

      本文标题:手写call bind apply

      本文链接:https://www.haomeiwen.com/subject/itzrpltx.html