主题
isMatchWith
js
_.isMatchWith(object, source, [customizer])此方法与 _.isMatch 类似,不同之处在于它接受 customizer,调用该方法可比较值。如果 customizer 返回 undefined,则比较将由该方法处理。customizer 使用五个参数调用:(objValue, srcValue, index|key, object, source)。
¥This method is like _.isMatch except that it accepts customizer which is invoked to compare values. If customizer returns undefined, comparisons are handled by the method instead. The customizer is invoked with five arguments: (objValue, srcValue, index|key, object, source).
新增于
¥Since
4.0.0
参数
¥Arguments
object(对象):要反转的对象。¥
object(Object): The object to inspect.source(对象):要匹配的属性值的对象。¥
source(Object): The object of property values to match.[customizer](函数):自定义比较的函数。¥
[customizer](Function): The function to customize comparisons.
返回
¥Returns
(布尔):如果 object 是匹配,则返回 true,否则返回 false。
¥(boolean): Returns true if object is a match, else false.
示例
¥Example
js
function isGreeting(value) {
return /^h(?:i|ello)$/.test(value);
}
function customizer(objValue, srcValue) {
if (isGreeting(objValue) && isGreeting(srcValue)) {
return true;
}
}
var object = { 'greeting': 'hello' };
var source = { 'greeting': 'hi' };
_.isMatchWith(object, source, customizer);
// => true