mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-01-31 15:27:50 +00:00
32 lines
706 B
JavaScript
32 lines
706 B
JavaScript
define(['../internal/baseProperty'], function(baseProperty) {
|
|
|
|
/**
|
|
* Creates a function which returns the property value of `key` on a given object.
|
|
*
|
|
* @static
|
|
* @memberOf _
|
|
* @category Utility
|
|
* @param {string} key The key of the property to get.
|
|
* @returns {Function} Returns the new function.
|
|
* @example
|
|
*
|
|
* var users = [
|
|
* { 'user': 'fred' },
|
|
* { 'user': 'barney' }
|
|
* ];
|
|
*
|
|
* var getName = _.property('user');
|
|
*
|
|
* _.map(users, getName);
|
|
* // => ['fred', barney']
|
|
*
|
|
* _.pluck(_.sortBy(users, getName), 'user');
|
|
* // => ['barney', 'fred']
|
|
*/
|
|
function property(key) {
|
|
return baseProperty(key + '');
|
|
}
|
|
|
|
return property;
|
|
});
|