用js实现call方法

Function.prototype.call2 = function (context, ...args) {
  var context = context || window;
  //改变this指向
  context.__proto__.fn = this;
  //调用函数
  var res = context.fn(...args);
  //删除多余属性
  delete context.__proto__.fn;
  return res;
}

posted @ 2019-12-14 09:55  詹姆斯小皇帝  阅读(532)  评论(0编辑  收藏  举报