手写bind函数

Function.prototype.myBind = function(content,...arg){
  let _this = this;
  return function(...arguments){
    _this.call(content,...arg.concat(arguments));
  }
}

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

var a = 1, b = 1;

function add(c,d){
  console.log(this.a+this.b+c+d);
}
//add();
let aFn = add.myBind(obj,1);
aFn(2);

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