mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-08 02:17:48 +00:00
Apply rest arguments transform.
This commit is contained in:
@@ -18,9 +18,9 @@ function createBind(func, bitmask, thisArg) {
|
|||||||
var isBind = bitmask & WRAP_BIND_FLAG,
|
var isBind = bitmask & WRAP_BIND_FLAG,
|
||||||
Ctor = createCtor(func);
|
Ctor = createCtor(func);
|
||||||
|
|
||||||
function wrapper() {
|
function wrapper(...args) {
|
||||||
var fn = (this && this !== root && this instanceof wrapper) ? Ctor : func;
|
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;
|
return wrapper;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,19 +18,19 @@ function shortOut(func) {
|
|||||||
var count = 0,
|
var count = 0,
|
||||||
lastCalled = 0;
|
lastCalled = 0;
|
||||||
|
|
||||||
return function() {
|
return function(...args) {
|
||||||
var stamp = nativeNow(),
|
var stamp = nativeNow(),
|
||||||
remaining = HOT_SPAN - (stamp - lastCalled);
|
remaining = HOT_SPAN - (stamp - lastCalled);
|
||||||
|
|
||||||
lastCalled = stamp;
|
lastCalled = stamp;
|
||||||
if (remaining > 0) {
|
if (remaining > 0) {
|
||||||
if (++count >= HOT_COUNT) {
|
if (++count >= HOT_COUNT) {
|
||||||
return arguments[0];
|
return args[0];
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
count = 0;
|
count = 0;
|
||||||
}
|
}
|
||||||
return func(...arguments);
|
return func(...args);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
4
after.js
4
after.js
@@ -32,9 +32,9 @@ function after(n, func) {
|
|||||||
throw new TypeError(FUNC_ERROR_TEXT);
|
throw new TypeError(FUNC_ERROR_TEXT);
|
||||||
}
|
}
|
||||||
n = toInteger(n);
|
n = toInteger(n);
|
||||||
return function() {
|
return function(...args) {
|
||||||
if (--n < 1) {
|
if (--n < 1) {
|
||||||
return func.apply(this, arguments);
|
return func.apply(this, args);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,9 +26,9 @@ function before(n, func) {
|
|||||||
throw new TypeError(FUNC_ERROR_TEXT);
|
throw new TypeError(FUNC_ERROR_TEXT);
|
||||||
}
|
}
|
||||||
n = toInteger(n);
|
n = toInteger(n);
|
||||||
return function() {
|
return function(...args) {
|
||||||
if (--n > 0) {
|
if (--n > 0) {
|
||||||
result = func.apply(this, arguments);
|
result = func.apply(this, args);
|
||||||
}
|
}
|
||||||
if (n <= 1) {
|
if (n <= 1) {
|
||||||
func = undefined;
|
func = undefined;
|
||||||
|
|||||||
@@ -33,11 +33,11 @@ import isArray from './isArray.js';
|
|||||||
* console.log(_.castArray(array) === array);
|
* console.log(_.castArray(array) === array);
|
||||||
* // => true
|
* // => true
|
||||||
*/
|
*/
|
||||||
function castArray() {
|
function castArray(...args) {
|
||||||
if (!arguments.length) {
|
if (!args.length) {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
var value = arguments[0];
|
var value = args[0];
|
||||||
return isArray(value) ? value : [value];
|
return isArray(value) ? value : [value];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -157,11 +157,11 @@ function debounce(func, wait, options) {
|
|||||||
return timerId === undefined ? result : trailingEdge(now());
|
return timerId === undefined ? result : trailingEdge(now());
|
||||||
}
|
}
|
||||||
|
|
||||||
function debounced() {
|
function debounced(...args) {
|
||||||
var time = now(),
|
var time = now(),
|
||||||
isInvoking = shouldInvoke(time);
|
isInvoking = shouldInvoke(time);
|
||||||
|
|
||||||
lastArgs = arguments;
|
lastArgs = args;
|
||||||
lastThis = this;
|
lastThis = this;
|
||||||
lastCallTime = time;
|
lastCallTime = time;
|
||||||
|
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ var propertyIsEnumerable = objectProto.propertyIsEnumerable;
|
|||||||
* _.isArguments([1, 2, 3]);
|
* _.isArguments([1, 2, 3]);
|
||||||
* // => false
|
* // => 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');
|
!propertyIsEnumerable.call(value, 'callee');
|
||||||
|
|
||||||
export default isArguments;
|
export default isArguments;
|
||||||
|
|||||||
Reference in New Issue
Block a user