Apply rest arguments transform.

This commit is contained in:
John-David Dalton
2017-01-06 15:49:42 -08:00
parent f4a6e9ede9
commit bf54267f0b
7 changed files with 15 additions and 15 deletions

View File

@@ -18,9 +18,9 @@ function createBind(func, bitmask, thisArg) {
var isBind = bitmask & WRAP_BIND_FLAG,
Ctor = createCtor(func);
function wrapper() {
function wrapper(...args) {
var fn = (this && this !== root && this instanceof wrapper) ? Ctor : func;
return fn.apply(isBind ? thisArg : this, arguments);
return fn.apply(isBind ? thisArg : this, args);
}
return wrapper;
}

View File

@@ -18,19 +18,19 @@ function shortOut(func) {
var count = 0,
lastCalled = 0;
return function() {
return function(...args) {
var stamp = nativeNow(),
remaining = HOT_SPAN - (stamp - lastCalled);
lastCalled = stamp;
if (remaining > 0) {
if (++count >= HOT_COUNT) {
return arguments[0];
return args[0];
}
} else {
count = 0;
}
return func(...arguments);
return func(...args);
};
}

View File

@@ -32,9 +32,9 @@ function after(n, func) {
throw new TypeError(FUNC_ERROR_TEXT);
}
n = toInteger(n);
return function() {
return function(...args) {
if (--n < 1) {
return func.apply(this, arguments);
return func.apply(this, args);
}
};
}

View File

@@ -26,9 +26,9 @@ function before(n, func) {
throw new TypeError(FUNC_ERROR_TEXT);
}
n = toInteger(n);
return function() {
return function(...args) {
if (--n > 0) {
result = func.apply(this, arguments);
result = func.apply(this, args);
}
if (n <= 1) {
func = undefined;

View File

@@ -33,11 +33,11 @@ import isArray from './isArray.js';
* console.log(_.castArray(array) === array);
* // => true
*/
function castArray() {
if (!arguments.length) {
function castArray(...args) {
if (!args.length) {
return [];
}
var value = arguments[0];
var value = args[0];
return isArray(value) ? value : [value];
}

View File

@@ -157,11 +157,11 @@ function debounce(func, wait, options) {
return timerId === undefined ? result : trailingEdge(now());
}
function debounced() {
function debounced(...args) {
var time = now(),
isInvoking = shouldInvoke(time);
lastArgs = arguments;
lastArgs = args;
lastThis = this;
lastCallTime = time;

View File

@@ -28,7 +28,7 @@ var propertyIsEnumerable = objectProto.propertyIsEnumerable;
* _.isArguments([1, 2, 3]);
* // => false
*/
var isArguments = baseIsArguments(function() { return arguments; }()) ? baseIsArguments : value => isObjectLike(value) && hasOwnProperty.call(value, 'callee') &&
var isArguments = baseIsArguments(function(...args) { return args; }()) ? baseIsArguments : value => isObjectLike(value) && hasOwnProperty.call(value, 'callee') &&
!propertyIsEnumerable.call(value, 'callee');
export default isArguments;