mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-04 17:07:49 +00:00
Rebuild dist files.
This commit is contained in:
35
dist/lodash.underscore.js
vendored
35
dist/lodash.underscore.js
vendored
@@ -4842,36 +4842,43 @@
|
||||
|
||||
/**
|
||||
* Resolves the value of property `key` on `object`. If `key` is a function
|
||||
* it will be invoked with the `this` binding of `object` and its result returned,
|
||||
* else the property value is returned. If `object` is falsey then `undefined`
|
||||
* is returned.
|
||||
* it will be invoked with the `this` binding of `object` and its result
|
||||
* returned, else the property value is returned. If `object` is `null` or
|
||||
* `undefined` then `undefined` is returned. If a default value is provided
|
||||
* it will be returned if the property value resolves to `undefined`.
|
||||
*
|
||||
* @static
|
||||
* @memberOf _
|
||||
* @category Utilities
|
||||
* @param {Object} object The object to inspect.
|
||||
* @param {string} key The name of the property to resolve.
|
||||
* @param {*} [defaultValue] The value returned if the property value
|
||||
* resolves to `undefined`.
|
||||
* @returns {*} Returns the resolved value.
|
||||
* @example
|
||||
*
|
||||
* var object = {
|
||||
* 'cheese': 'crumpets',
|
||||
* 'stuff': function() {
|
||||
* return 'nonsense';
|
||||
* 'name': 'fred',
|
||||
* 'age': function() {
|
||||
* return 40;
|
||||
* }
|
||||
* };
|
||||
*
|
||||
* _.result(object, 'cheese');
|
||||
* // => 'crumpets'
|
||||
* _.result(object, 'name');
|
||||
* // => 'fred'
|
||||
*
|
||||
* _.result(object, 'stuff');
|
||||
* // => 'nonsense'
|
||||
* _.result(object, 'age');
|
||||
* // => 40
|
||||
*
|
||||
* _.result(object, 'employer', 'slate');
|
||||
* // => 'slate'
|
||||
*/
|
||||
function result(object, key) {
|
||||
if (object) {
|
||||
var value = object[key];
|
||||
return isFunction(value) ? object[key]() : value;
|
||||
function result(object, key, defaultValue) {
|
||||
if (object == null) {
|
||||
return defaultValue;
|
||||
}
|
||||
var value = typeof object[key] != 'undefined' ? object[key] : defaultValue;
|
||||
return isFunction(value) ? object[key]() : value;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user