mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-10 19:07:49 +00:00
Remove arguments references where possible.
This commit is contained in:
@@ -10,11 +10,10 @@ import isObject from './isObject.js';
|
|||||||
* @returns {Function} Returns the new wrapped function.
|
* @returns {Function} Returns the new wrapped function.
|
||||||
*/
|
*/
|
||||||
function createCtor(Ctor) {
|
function createCtor(Ctor) {
|
||||||
return function() {
|
return function(...args) {
|
||||||
// Use a `switch` statement to work with class constructors. See
|
// Use a `switch` statement to work with class constructors. See
|
||||||
// http://ecma-international.org/ecma-262/7.0/#sec-ecmascript-function-objects-call-thisargument-argumentslist
|
// http://ecma-international.org/ecma-262/7.0/#sec-ecmascript-function-objects-call-thisargument-argumentslist
|
||||||
// for more details.
|
// for more details.
|
||||||
const args = arguments;
|
|
||||||
switch (args.length) {
|
switch (args.length) {
|
||||||
case 0: return new Ctor;
|
case 0: return new Ctor;
|
||||||
case 1: return new Ctor(args[0]);
|
case 1: return new Ctor(args[0]);
|
||||||
|
|||||||
@@ -18,16 +18,9 @@ import root from './_root.js';
|
|||||||
function createCurry(func, bitmask, arity) {
|
function createCurry(func, bitmask, arity) {
|
||||||
const Ctor = createCtor(func);
|
const Ctor = createCtor(func);
|
||||||
|
|
||||||
function wrapper() {
|
function wrapper(...args) {
|
||||||
let length = arguments.length;
|
let length = args.length;
|
||||||
let index = length;
|
|
||||||
|
|
||||||
const args = Array(length);
|
|
||||||
const placeholder = getHolder(wrapper);
|
const placeholder = getHolder(wrapper);
|
||||||
|
|
||||||
while (index--) {
|
|
||||||
args[index] = arguments[index];
|
|
||||||
}
|
|
||||||
const holders = (length < 3 && args[0] !== placeholder && args[length - 1] !== placeholder)
|
const holders = (length < 3 && args[0] !== placeholder && args[length - 1] !== placeholder)
|
||||||
? []
|
? []
|
||||||
: replaceHolders(args, placeholder);
|
: replaceHolders(args, placeholder);
|
||||||
|
|||||||
13
concat.js
13
concat.js
@@ -24,18 +24,7 @@ import isArray from './isArray.js';
|
|||||||
* console.log(array);
|
* console.log(array);
|
||||||
* // => [1]
|
* // => [1]
|
||||||
*/
|
*/
|
||||||
function concat() {
|
function concat(array, ...values) {
|
||||||
const length = arguments.length;
|
|
||||||
if (!length) {
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
const args = Array(length - 1);
|
|
||||||
const array = arguments[0];
|
|
||||||
let index = length;
|
|
||||||
|
|
||||||
while (index--) {
|
|
||||||
args[index - 1] = arguments[index];
|
|
||||||
}
|
|
||||||
return arrayPush(isArray(array) ? copyArray(array) : [array], baseFlatten(args, 1));
|
return arrayPush(isArray(array) ? copyArray(array) : [array], baseFlatten(args, 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -50,8 +50,8 @@ function memoize(func, resolver) {
|
|||||||
if (typeof func != 'function' || (resolver != null && typeof resolver != 'function')) {
|
if (typeof func != 'function' || (resolver != null && typeof resolver != 'function')) {
|
||||||
throw new TypeError(FUNC_ERROR_TEXT);
|
throw new TypeError(FUNC_ERROR_TEXT);
|
||||||
}
|
}
|
||||||
const memoized = function() {
|
const memoized = function(...args) {
|
||||||
const args = arguments, key = resolver ? resolver.apply(this, args) : args[0];
|
const key = resolver ? resolver.apply(this, args) : args[0];
|
||||||
const cache = memoized.cache;
|
const cache = memoized.cache;
|
||||||
|
|
||||||
if (cache.has(key)) {
|
if (cache.has(key)) {
|
||||||
|
|||||||
@@ -24,14 +24,7 @@ function negate(predicate) {
|
|||||||
if (typeof predicate != 'function') {
|
if (typeof predicate != 'function') {
|
||||||
throw new TypeError(FUNC_ERROR_TEXT);
|
throw new TypeError(FUNC_ERROR_TEXT);
|
||||||
}
|
}
|
||||||
return function() {
|
return function(...args) {
|
||||||
const args = arguments;
|
|
||||||
switch (args.length) {
|
|
||||||
case 0: return !predicate.call(this);
|
|
||||||
case 1: return !predicate.call(this, args[0]);
|
|
||||||
case 2: return !predicate.call(this, args[0], args[1]);
|
|
||||||
case 3: return !predicate.call(this, args[0], args[1], args[2]);
|
|
||||||
}
|
|
||||||
return !predicate.apply(this, args);
|
return !predicate.apply(this, args);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user