Back to Underscore

restArguments.js

docs/modules/restArguments.html

1.13.8678 B
Original Source
exportdefaultfunctionrestArguments(func, startIndex) {
  startIndex = startIndex ==null? func.length-1: +startIndex;returnfunction() {varlength =Math.max(arguments.length- startIndex,0),
        rest =Array(length),
        index =0;for(; index < length; index++) {
      rest[index] =arguments[index + startIndex];
    }switch(startIndex) {case0:returnfunc.call(this, rest);case1:returnfunc.call(this,arguments[0], rest);case2:returnfunc.call(this,arguments[0],arguments[1], rest);
    }varargs =Array(startIndex +1);for(index =0; index < startIndex; index++) {
      args[index] =arguments[index];
    }
    args[startIndex] = rest;returnfunc.apply(this, args);
  };
}