mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-08 02:17:48 +00:00
Bump to v4.14.0.
This commit is contained in:
30
rest.js
30
rest.js
@@ -1,12 +1,9 @@
|
||||
import apply from './_apply.js';
|
||||
import baseRest from './_baseRest.js';
|
||||
import toInteger from './toInteger.js';
|
||||
|
||||
/** Used as the `TypeError` message for "Functions" methods. */
|
||||
var FUNC_ERROR_TEXT = 'Expected a function';
|
||||
|
||||
/* Built-in method references for those with the same name as other `lodash` methods. */
|
||||
var nativeMax = Math.max;
|
||||
|
||||
/**
|
||||
* Creates a function that invokes `func` with the `this` binding of the
|
||||
* created function and arguments from `start` and beyond provided as
|
||||
@@ -36,29 +33,8 @@ function rest(func, start) {
|
||||
if (typeof func != 'function') {
|
||||
throw new TypeError(FUNC_ERROR_TEXT);
|
||||
}
|
||||
start = nativeMax(start === undefined ? (func.length - 1) : toInteger(start), 0);
|
||||
return function() {
|
||||
var args = arguments,
|
||||
index = -1,
|
||||
length = nativeMax(args.length - start, 0),
|
||||
array = Array(length);
|
||||
|
||||
while (++index < length) {
|
||||
array[index] = args[start + index];
|
||||
}
|
||||
switch (start) {
|
||||
case 0: return func.call(this, array);
|
||||
case 1: return func.call(this, args[0], array);
|
||||
case 2: return func.call(this, args[0], args[1], array);
|
||||
}
|
||||
var otherArgs = Array(start + 1);
|
||||
index = -1;
|
||||
while (++index < start) {
|
||||
otherArgs[index] = args[index];
|
||||
}
|
||||
otherArgs[start] = array;
|
||||
return apply(func, this, otherArgs);
|
||||
};
|
||||
start = start === undefined ? start : toInteger(start);
|
||||
return baseRest(func, start);
|
||||
}
|
||||
|
||||
export default rest;
|
||||
|
||||
Reference in New Issue
Block a user