手写call

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

Function.prototype.myCall = function(content,...arg){
  let _this = this
  let sy = Symbol();
  content[sy] = _this;
  return content[sy](...arg);
}

function add(c,d){
  console.log(this.a + this.b + c + d)
}
add.myCall(obj,2,4);

原文地址:https://www.cnblogs.com/jayking1314/p/14874252.html