call

Function.prototype.myCall = function(){
    var object = arguments[0];
    var arr = [];
    for(var i = 1; i < arguments.length; i++){
        arr.push(arguments[i]);
    }
    object.__proto__._fn = this;
    var result = object._fn(...arr);
    delete object.__proto__._fn;
    return result;
}

 

apply

Function.prototype.myApply = function(object,arr){
    object.__proto__._fn = this;
    var result = object._fn(...arr);
    delete object.__proto__._fn;
    return result;
}

 

相关文章:

  • 2022-03-08
  • 2022-12-23
  • 2022-12-23
  • 2023-02-08
  • 2023-03-15
  • 2022-01-31
猜你喜欢
  • 2021-07-23
  • 2021-05-16
  • 2021-06-19
  • 2022-12-23
  • 2021-07-06
  • 2022-12-23
  • 2023-03-20
相关资源
相似解决方案