mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-03 00:27:50 +00:00
Bump to v3.7.0.
This commit is contained in:
26
internal/invokePath.js
Normal file
26
internal/invokePath.js
Normal file
@@ -0,0 +1,26 @@
|
||||
import baseGet from './baseGet';
|
||||
import baseSlice from './baseSlice';
|
||||
import isKey from './isKey';
|
||||
import last from '../array/last';
|
||||
import toPath from './toPath';
|
||||
|
||||
/**
|
||||
* Invokes the method at `path` on `object`.
|
||||
*
|
||||
* @private
|
||||
* @param {Object} object The object to query.
|
||||
* @param {Array|string} path The path of the method to invoke.
|
||||
* @param {Array} args The arguments to invoke the method with.
|
||||
* @returns {*} Returns the result of the invoked method.
|
||||
*/
|
||||
function invokePath(object, path, args) {
|
||||
if (object != null && !isKey(path, object)) {
|
||||
path = toPath(path);
|
||||
object = path.length == 1 ? object : baseGet(object, baseSlice(path, 0, -1));
|
||||
path = last(path);
|
||||
}
|
||||
var func = object == null ? object : object[path];
|
||||
return func == null ? undefined : func.apply(object, args);
|
||||
}
|
||||
|
||||
export default invokePath;
|
||||
Reference in New Issue
Block a user