bind方法的内部实现代码

Function.prototype.myBind = function (target) {
  var self = this;
  var args = [].slice.call(arguments, 1);
  var temp = function () {};
  var f = function () {
    var _arg = [].slice.call(arguments, 0);
    return self.apply( this instanceof temp ? this : (target || window), args.concat(_arg));
  }
  temp.prototype = self.prototype;
  f.prototype = new temp();
  return f;
}

  

posted @ 2019-01-17 14:33  red东  阅读(262)  评论(0编辑  收藏  举报