mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-01 23:57: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.
|
||||
*/
|
||||
function createCtor(Ctor) {
|
||||
return function() {
|
||||
return function(...args) {
|
||||
// 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
|
||||
// for more details.
|
||||
const args = arguments;
|
||||
switch (args.length) {
|
||||
case 0: return new Ctor;
|
||||
case 1: return new Ctor(args[0]);
|
||||
|
||||
@@ -18,16 +18,9 @@ import root from './_root.js';
|
||||
function createCurry(func, bitmask, arity) {
|
||||
const Ctor = createCtor(func);
|
||||
|
||||
function wrapper() {
|
||||
let length = arguments.length;
|
||||
let index = length;
|
||||
|
||||
const args = Array(length);
|
||||
function wrapper(...args) {
|
||||
let length = args.length;
|
||||
const placeholder = getHolder(wrapper);
|
||||
|
||||
while (index--) {
|
||||
args[index] = arguments[index];
|
||||
}
|
||||
const holders = (length < 3 && args[0] !== placeholder && args[length - 1] !== placeholder)
|
||||
? []
|
||||
: replaceHolders(args, placeholder);
|
||||
|
||||
13
concat.js
13
concat.js
@@ -24,18 +24,7 @@ import isArray from './isArray.js';
|
||||
* console.log(array);
|
||||
* // => [1]
|
||||
*/
|
||||
function concat() {
|
||||
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];
|
||||
}
|
||||
function concat(array, ...values) {
|
||||
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')) {
|
||||
throw new TypeError(FUNC_ERROR_TEXT);
|
||||
}
|
||||
const memoized = function() {
|
||||
const args = arguments, key = resolver ? resolver.apply(this, args) : args[0];
|
||||
const memoized = function(...args) {
|
||||
const key = resolver ? resolver.apply(this, args) : args[0];
|
||||
const cache = memoized.cache;
|
||||
|
||||
if (cache.has(key)) {
|
||||
|
||||
@@ -24,14 +24,7 @@ function negate(predicate) {
|
||||
if (typeof predicate != 'function') {
|
||||
throw new TypeError(FUNC_ERROR_TEXT);
|
||||
}
|
||||
return function() {
|
||||
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 function(...args) {
|
||||
return !predicate.apply(this, args);
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user