Files
lodash/utility/matches.js
2015-12-16 17:45:39 -08:00

34 lines
920 B
JavaScript

define(['../internal/baseClone', '../internal/baseMatches'], function(baseClone, 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(baseClone(source, true));
}
return matches;
});