From 627bfe6bfacb85c9ba668095b40822d8eb94c7a5 Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Mon, 9 Jan 2017 18:30:38 -0800 Subject: [PATCH] Remove `arguments` references where possible. --- _createCtor.js | 3 +-- _createCurry.js | 11 ++--------- concat.js | 13 +------------ memoize.js | 4 ++-- negate.js | 9 +-------- 5 files changed, 7 insertions(+), 33 deletions(-) diff --git a/_createCtor.js b/_createCtor.js index 582355201..88a7a449a 100644 --- a/_createCtor.js +++ b/_createCtor.js @@ -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]); diff --git a/_createCurry.js b/_createCurry.js index 07575cb48..837841283 100644 --- a/_createCurry.js +++ b/_createCurry.js @@ -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); diff --git a/concat.js b/concat.js index 70dfa769d..914adacb1 100644 --- a/concat.js +++ b/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)); } diff --git a/memoize.js b/memoize.js index cff4ca0b5..cc11dbc19 100644 --- a/memoize.js +++ b/memoize.js @@ -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)) { diff --git a/negate.js b/negate.js index 76edd879a..2f72e99a9 100644 --- a/negate.js +++ b/negate.js @@ -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); }; }