mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-10 19:07:49 +00:00
Bump to v3.0.0.
This commit is contained in:
26
utility/propertyOf.js
Normal file
26
utility/propertyOf.js
Normal file
@@ -0,0 +1,26 @@
|
||||
/**
|
||||
* The inverse of `_.property`; this method creates a function which returns
|
||||
* the property value of a given key on `object`.
|
||||
*
|
||||
* @static
|
||||
* @memberOf _
|
||||
* @category Utility
|
||||
* @param {Object} object The object to inspect.
|
||||
* @returns {Function} Returns the new function.
|
||||
* @example
|
||||
*
|
||||
* var object = { 'user': 'fred', 'age': 40, 'active': true };
|
||||
* _.map(['active', 'user'], _.propertyOf(object));
|
||||
* // => [true, 'fred']
|
||||
*
|
||||
* var object = { 'a': 3, 'b': 1, 'c': 2 };
|
||||
* _.sortBy(['a', 'b', 'c'], _.propertyOf(object));
|
||||
* // => ['b', 'c', 'a']
|
||||
*/
|
||||
function propertyOf(object) {
|
||||
return function(key) {
|
||||
return object == null ? undefined : object[key];
|
||||
};
|
||||
}
|
||||
|
||||
export default propertyOf;
|
||||
Reference in New Issue
Block a user