MCPcopy
hub / github.com/lodash/lodash / result

Function result

lodash.js:13722–13742  ·  lodash.js::result

* This method is like `_.get` except that if the resolved value is a * function it's invoked with the `this` binding of its parent object and * its result is returned. * * @static * @since 0.1.0 * @memberOf _ * @category Object * @param {Object} object The obj

(object, path, defaultValue)

Source from the content-addressed store, hash-verified

13720 * class="cm">// => class="st">'default'
13721 */
13722 function result(object, path, defaultValue) {
13723 path = castPath(path, object);
13724
13725 var index = -1,
13726 length = path.length;
13727
13728 class="cm">// Ensure the loop is entered when path is empty.
13729 if (!length) {
13730 length = 1;
13731 object = undefined;
13732 }
13733 while (++index < length) {
13734 var value = object == null ? undefined : object[toKey(path[index])];
13735 if (value === undefined) {
13736 index = length;
13737 value = defaultValue;
13738 }
13739 object = isFunction(value) ? value.call(object) : value;
13740 }
13741 return object;
13742 }
13743
13744 /**
13745 * Sets the value at `path` of `object`. If a portion of `path` doesn't exist,

Callers 1

getIterateeFunction · 0.85

Calls 3

castPathFunction · 0.85
toKeyFunction · 0.85
isFunctionFunction · 0.85

Tested by

no test coverage detected