主题
isEqualWith
js
_.isEqualWith(value, other, [customizer])
此方法与 _.isEqual
类似,不同之处在于它接受 customizer
,调用该方法可比较值。如果 customizer
返回 undefined
,则比较将由该方法处理。customizer
使用最多六个参数来调用:(objValue, othValue [, index|key, object, other, stack])。
¥This method is like _.isEqual
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 up to six arguments: (objValue, othValue [, index|key, object, other, stack]).
新增于
¥Since
4.0.0
参数
¥Arguments
value
(*):要比较的值。¥
value
()*: The value to compare.other
(*):要比较的另一个值。¥
other
()*: The other value to compare.[customizer]
(函数):自定义比较的函数。¥
[customizer]
(Function): The function to customize comparisons.
返回
¥Returns
(布尔):如果值相等,则返回 true
,否则返回 false
。
¥(boolean): Returns true
if the values are equivalent, else false
.
示例
¥Example
js
function isGreeting(value) {
return /^h(?:i|ello)$/.test(value);
}
function customizer(objValue, othValue) {
if (isGreeting(objValue) && isGreeting(othValue)) {
return true;
}
}
var array = ['hello', 'goodbye'];
var other = ['hi', 'goodbye'];
_.isEqualWith(array, other, customizer);
// => true