Files
lodash/utility/propertyOf.js
John-David Dalton 9724afd7a6 Bump to v3.6.0.
2015-12-16 17:49:07 -08:00

33 lines
793 B
JavaScript

define([], function() {
/** Used as a safe reference for `undefined` in pre-ES5 environments. */
var undefined;
/**
* The opposite 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 = { 'a': 3, 'b': 1, 'c': 2 };
*
* _.map(['a', 'c'], _.propertyOf(object));
* // => [3, 2]
*
* _.sortBy(['a', 'b', 'c'], _.propertyOf(object));
* // => ['b', 'c', 'a']
*/
function propertyOf(object) {
return function(key) {
return object == null ? undefined : object[key];
};
}
return propertyOf;
});