mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-01 23:57:49 +00:00
Remove apply.
This commit is contained in:
@@ -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
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
5
cond.js
5
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
4
over.js
4
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))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user