mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-11 11:27:50 +00:00
Add _.method and _.methodOf docs. [ci skip]
This commit is contained in:
@@ -11254,12 +11254,52 @@
|
|||||||
return baseMatchesProperty(path, baseClone(value, true));
|
return baseMatchesProperty(path, baseClone(value, true));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a function which invokes the method at `path` on a given object.
|
||||||
|
*
|
||||||
|
* @static
|
||||||
|
* @memberOf _
|
||||||
|
* @category Utility
|
||||||
|
* @param {Array|string} path The path of the method to invoke.
|
||||||
|
* @returns {Function} Returns the new function.
|
||||||
|
* @example
|
||||||
|
*
|
||||||
|
* var objects = [
|
||||||
|
* { 'a': _.constant(2) },
|
||||||
|
* { 'a': _.constant(1) }
|
||||||
|
* ];
|
||||||
|
*
|
||||||
|
* _.map(objects, _.method('a'));
|
||||||
|
* // => [2, 1]
|
||||||
|
*
|
||||||
|
* _.invoke(_.sortBy(objects, _.method('a')), 'a');
|
||||||
|
* // => [1, 2]
|
||||||
|
*/
|
||||||
var method = restParam(function(path, args) {
|
var method = restParam(function(path, args) {
|
||||||
return function(object) {
|
return function(object) {
|
||||||
return baseMethod(object, path, args);
|
return baseMethod(object, path, args);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The opposite of `_.method`; this method creates a function which invokes
|
||||||
|
* the method at a given path on `object`.
|
||||||
|
*
|
||||||
|
* @static
|
||||||
|
* @memberOf _
|
||||||
|
* @category Utility
|
||||||
|
* @param {Object} object The object to inspect.
|
||||||
|
* @returns {Function} Returns the new function.
|
||||||
|
* @example
|
||||||
|
*
|
||||||
|
* var object = { 'a': _.constant(3), 'b': _.constant(1), 'c': _.constant(2) };
|
||||||
|
*
|
||||||
|
* _.map(['a', 'c'], _.methodOf(object));
|
||||||
|
* // => [3, 2]
|
||||||
|
*
|
||||||
|
* _.sortBy(['a', 'b', 'c'], _.methodOf(object));
|
||||||
|
* // => ['b', 'c', 'a']
|
||||||
|
*/
|
||||||
var methodOf = restParam(function(object, args) {
|
var methodOf = restParam(function(object, args) {
|
||||||
return function(path) {
|
return function(path) {
|
||||||
return baseMethod(object, path, args);
|
return baseMethod(object, path, args);
|
||||||
@@ -11394,7 +11434,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a function which returns the property value of `path` on a
|
* Creates a function which returns the property value at `path` on a
|
||||||
* given object.
|
* given object.
|
||||||
*
|
*
|
||||||
* @static
|
* @static
|
||||||
@@ -11404,18 +11444,16 @@
|
|||||||
* @returns {Function} Returns the new function.
|
* @returns {Function} Returns the new function.
|
||||||
* @example
|
* @example
|
||||||
*
|
*
|
||||||
* var users = [
|
* var objects = [
|
||||||
* { 'user': 'fred' },
|
* { 'a': 2 },
|
||||||
* { 'user': 'barney' }
|
* { 'a': 1 }
|
||||||
* ];
|
* ];
|
||||||
*
|
*
|
||||||
* var getName = _.property('user');
|
* _.map(objects, _.property('a'));
|
||||||
|
* // => [2, 1]
|
||||||
*
|
*
|
||||||
* _.map(users, getName);
|
* _.pluck(_.sortBy(objects, _.property('a')), 'a');
|
||||||
* // => ['fred', 'barney']
|
* // => [1, 2]
|
||||||
*
|
|
||||||
* _.pluck(_.sortBy(users, getName), 'user');
|
|
||||||
* // => ['barney', 'fred']
|
|
||||||
*/
|
*/
|
||||||
function property(path) {
|
function property(path) {
|
||||||
return isKey(path) ? baseProperty(path) : basePropertyDeep(path);
|
return isKey(path) ? baseProperty(path) : basePropertyDeep(path);
|
||||||
@@ -11423,7 +11461,7 @@
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* The opposite of `_.property`; this method creates a function which returns
|
* The opposite of `_.property`; this method creates a function which returns
|
||||||
* the property value of a given path on `object`.
|
* the property value at a given path on `object`.
|
||||||
*
|
*
|
||||||
* @static
|
* @static
|
||||||
* @memberOf _
|
* @memberOf _
|
||||||
|
|||||||
Reference in New Issue
Block a user