mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-01 15:57:48 +00:00
34 lines
873 B
JavaScript
34 lines
873 B
JavaScript
define(['../internal/baseMatches'], function(baseMatches) {
|
|
|
|
/**
|
|
* Creates a function which performs a deep comparison between a given object
|
|
* and `source`, returning `true` if the given object has equivalent property
|
|
* values, else `false`.
|
|
*
|
|
* @static
|
|
* @memberOf _
|
|
* @category Utility
|
|
* @param {Object} source The object of property values to match.
|
|
* @returns {Function} Returns the new function.
|
|
* @example
|
|
*
|
|
* var users = [
|
|
* { 'user': 'fred', 'age': 40 },
|
|
* { 'user': 'barney', 'age': 36 }
|
|
* ];
|
|
*
|
|
* var matchesAge = _.matches({ 'age': 36 });
|
|
*
|
|
* _.filter(users, matchesAge);
|
|
* // => [{ 'user': 'barney', 'age': 36 }]
|
|
*
|
|
* _.find(users, matchesAge);
|
|
* // => { 'user': 'barney', 'age': 36 }
|
|
*/
|
|
function matches(source) {
|
|
return baseMatches(source, true);
|
|
}
|
|
|
|
return matches;
|
|
});
|