diff --git a/.internal/apply.js b/.internal/apply.js deleted file mode 100644 index 45295ac6e..000000000 --- a/.internal/apply.js +++ /dev/null @@ -1,21 +0,0 @@ -/** - * A faster alternative to `Function#apply`, this function invokes `func` - * with the `this` binding of `thisArg` and the arguments of `args`. - * - * @private - * @param {Function} func The function to invoke. - * @param {*} thisArg The `this` binding of `func`. - * @param {Array} args The arguments to invoke `func` with. - * @returns {*} Returns the result of `func`. - */ -function apply(func, thisArg, args) { - switch (args.length) { - case 0: return func.call(thisArg) - case 1: return func.call(thisArg, args[0]) - case 2: return func.call(thisArg, args[0], args[1]) - case 3: return func.call(thisArg, args[0], args[1], args[2]) - } - return func.apply(thisArg, args) -} - -export default apply diff --git a/attempt.js b/attempt.js index c335dc6cf..8f792de79 100644 --- a/attempt.js +++ b/attempt.js @@ -1,4 +1,3 @@ -import apply from './.internal/apply.js' import isError from './isError.js' /** @@ -22,7 +21,7 @@ import isError from './isError.js' */ function attempt(func, ...args) { try { - return apply(func, undefined, args) + return func.apply(undefined, args) } catch (e) { return isError(e) ? e : new Error(e) } diff --git a/cond.js b/cond.js index 5c632a7ad..3f5743746 100644 --- a/cond.js +++ b/cond.js @@ -1,4 +1,3 @@ -import apply from './.internal/apply.js' import arrayMap from './.internal/arrayMap.js' /** @@ -42,8 +41,8 @@ function cond(pairs) { let index = -1 while (++index < length) { const pair = pairs[index] - if (apply(pair[0], this, args)) { - return apply(pair[1], this, args) + if (pair[0].apply(this, args)) { + return pair[1].apply(this, args) } } } diff --git a/defaultsDeep.js b/defaultsDeep.js index 1ee4bdf6a..ae942f0cb 100644 --- a/defaultsDeep.js +++ b/defaultsDeep.js @@ -1,4 +1,3 @@ -import apply from './.internal/apply.js' import customDefaultsMerge from './.internal/customDefaultsMerge.js' import mergeWith from './mergeWith.js' @@ -21,7 +20,7 @@ import mergeWith from './mergeWith.js' */ function defaultsDeep(...args) { args.push(undefined, customDefaultsMerge) - return apply(mergeWith, undefined, args) + return mergeWith.apply(undefined, args) } export default defaultsDeep diff --git a/invoke.js b/invoke.js index 006977e1f..6767b99d2 100644 --- a/invoke.js +++ b/invoke.js @@ -1,4 +1,3 @@ -import apply from './.internal/apply.js' import castPath from './.internal/castPath.js' import last from './last.js' import parent from './.internal/parent.js' @@ -24,7 +23,7 @@ function invoke(object, path, args) { path = castPath(path, object) object = parent(object, path) const func = object == null ? object : object[toKey(last(path))] - return func == null ? undefined : apply(func, object, args) + return func == null ? undefined : func.apply(object, args) } export default invoke diff --git a/invokeMap.js b/invokeMap.js index b485c2d8f..330b197c1 100644 --- a/invokeMap.js +++ b/invokeMap.js @@ -1,4 +1,3 @@ -import apply from './.internal/apply.js' import baseEach from './.internal/baseEach.js' import invoke from './invoke.js' import isArrayLike from './isArrayLike.js' @@ -30,7 +29,7 @@ function invokeMap(collection, path, args) { const result = isArrayLike(collection) ? Array(collection.length) : [] baseEach(collection, value => { - result[++index] = isFunc ? apply(path, value, args) : invoke(value, path, args) + result[++index] = isFunc ? path.apply(value, args) : invoke(value, path, args) }) return result } diff --git a/over.js b/over.js index a769a24ae..df3684e62 100644 --- a/over.js +++ b/over.js @@ -1,4 +1,3 @@ -import apply from './.internal/apply.js' import arrayMap from './.internal/arrayMap.js' /** @@ -19,8 +18,7 @@ import arrayMap from './.internal/arrayMap.js' */ function over(iteratees) { return function(...args) { - const thisArg = this - return arrayMap(iteratees, iteratee => apply(iteratee, thisArg, args)) + return arrayMap(iteratees, iteratee => iteratee.apply(this, args)) } } diff --git a/overArgs.js b/overArgs.js index b0b13df2e..7a1479ec6 100644 --- a/overArgs.js +++ b/overArgs.js @@ -1,4 +1,3 @@ -import apply from './.internal/apply.js' /** * Creates a function that invokes `func` with its arguments transformed. @@ -35,7 +34,7 @@ function overArgs(func, transforms) { while (++index < length) { args[index] = transforms[index].call(this, args[index]) } - return apply(func, this, args) + return func.apply(this, args) } } diff --git a/overEvery.js b/overEvery.js index 6607435b4..1b8a20ad4 100644 --- a/overEvery.js +++ b/overEvery.js @@ -1,4 +1,3 @@ -import apply from './.internal/apply.js' import arrayEvery from './.internal/arrayEvery.js' /** @@ -25,8 +24,7 @@ import arrayEvery from './.internal/arrayEvery.js' */ function overEvery(iteratees) { return function(...args) { - const thisArg = this - return arrayEvery(iteratees, iteratee => apply(iteratee, thisArg, args)) + return arrayEvery(iteratees, iteratee => iteratee.apply(this, args)) } } diff --git a/overSome.js b/overSome.js index b9342caef..bf36b7754 100644 --- a/overSome.js +++ b/overSome.js @@ -1,4 +1,3 @@ -import apply from './.internal/apply.js' import arraySome from './.internal/arraySome.js' /** @@ -25,8 +24,7 @@ import arraySome from './.internal/arraySome.js' */ function overSome(iteratees) { return function(...args) { - const thisArg = this - return arraySome(iteratees, iteratee => apply(iteratee, thisArg, args)) + return arraySome(iteratees, iteratee => iteratee.apply(this, args)) } } diff --git a/unzipWith.js b/unzipWith.js index bbca749f9..c174859ac 100644 --- a/unzipWith.js +++ b/unzipWith.js @@ -1,4 +1,3 @@ -import apply from './.internal/apply.js' import arrayMap from './.internal/arrayMap.js' import unzip from './unzip.js' @@ -26,7 +25,7 @@ function unzipWith(array, iteratee) { return [] } const result = unzip(array) - return arrayMap(result, group => apply(iteratee, undefined, group)) + return arrayMap(result, group => iteratee.apply(undefined, group)) } export default unzipWith