call、apply、bind

2019-06-27  本文已影响0人  糕糕AA
       function mySayYourWeapon(num, num2) {
          sayYourWeapon.apply(zoro, arguments) 
        }
      if (!Function.prototype.bind) {
        Function.prototype.bind = function(oThis) {
          if (typeof this !== 'function') {
            throw new TypeError('Function.prototype.bind - what is trying to be bound is not callable');
          }
          var aArgs = Array.prototype.slice.call(arguments, 1);
          var fToBind = this;
          var fNOP = function() {};
          var fBound  = function() {
              return fToBind.apply(this instanceof fBound ? this : oThis, aArgs.concat(Array.prototype.slice.call(arguments)));
          };
          if (this.prototype) {
            fNOP.prototype = this.prototype;
          }
          fBound.prototype = new fNOP();
          return fBound;
        };
      }
上一篇下一篇

猜你喜欢

热点阅读