手写apply

时间:2021-06-11 12:16:14   收藏:0   阅读:24

let obj = {
  a:1,
  b:2
}

Function.prototype.myApply = function(content,arr){
  console.log(‘myApply‘);
  let _this = this;
  let sy = Symbol();
  content[sy] = _this;
  return content[sy](...arr);
}

function add(c,d,e){
  console.log(this.a + this.b + c + d + e);
}
add.myApply(obj,[2,4,1]);

原文:https://www.cnblogs.com/jayking1314/p/14874280.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!