mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-09 10:27:49 +00:00
Bump to v4.0.0.
This commit is contained in:
29
property.js
Normal file
29
property.js
Normal file
@@ -0,0 +1,29 @@
|
||||
define(['./internal/baseProperty', './internal/basePropertyDeep', './internal/isKey'], function(baseProperty, basePropertyDeep, isKey) {
|
||||
|
||||
/**
|
||||
* Creates a function that returns the value at `path` of a given object.
|
||||
*
|
||||
* @static
|
||||
* @memberOf _
|
||||
* @category Util
|
||||
* @param {Array|string} path The path of the property to get.
|
||||
* @returns {Function} Returns the new function.
|
||||
* @example
|
||||
*
|
||||
* var objects = [
|
||||
* { 'a': { 'b': { 'c': 2 } } },
|
||||
* { 'a': { 'b': { 'c': 1 } } }
|
||||
* ];
|
||||
*
|
||||
* _.map(objects, _.property('a.b.c'));
|
||||
* // => [2, 1]
|
||||
*
|
||||
* _.map(_.sortBy(objects, _.property(['a', 'b', 'c'])), 'a.b.c');
|
||||
* // => [1, 2]
|
||||
*/
|
||||
function property(path) {
|
||||
return isKey(path) ? baseProperty(path) : basePropertyDeep(path);
|
||||
}
|
||||
|
||||
return property;
|
||||
});
|
||||
Reference in New Issue
Block a user