Remove arguments references where possible.

This commit is contained in:
John-David Dalton
2017-01-09 18:30:38 -08:00
parent f2c49500ee
commit 627bfe6bfa
5 changed files with 7 additions and 33 deletions

View File

@@ -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]);

View File

@@ -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);

View File

@@ -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));
}

View File

@@ -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)) {

View File

@@ -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);
};
}