_.isEqualWith(value, other, [customizer])

137ui

_.isEqualWith(value, other, [customizer])

_.isEqualWith此方法相似isEqual区别是它接受一个自定义比较方法。若是自定义比较方法返回值是undefined,比较结果就由baseIsEqual来处理spa

参数code

value (*): 须要比较的值
other (*): 须要比较的另一个值
[customizer] (Function): 自定义比较方法blog

返回值it

(boolean): 若是两个值相等返回true,不然falseio

例子function

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

源代码class

import baseIsEqual from './.internal/baseIsEqual.js'

/** * 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 * @category Lang * @param {*} value The value to compare. * @param {*} other The other value to compare. * @param {Function} [customizer] The function to customize comparisons. * @returns {boolean} Returns `true` if the values are equivalent, else `false`. * @example * * function isGreeting(value) { * return /^h(?:i|ello)$/.test(value) * } * * function customizer(objValue, othValue) { * if (isGreeting(objValue) && isGreeting(othValue)) { * return true * } * } * * const array = ['hello', 'goodbye'] * const other = ['hi', 'goodbye'] * * isEqualWith(array, other, customizer) * // => true */
//此方法相似isEqual区别是它接受一个自定义比较方法。若是自定义比较方法返回值是undefined,比较结果就由baseIsEqual来处理
function isEqualWith(value, other, customizer) { customizer = typeof customizer == 'function' ? customizer : undefined//判断是否传递了customizer
  const result = customizer ? customizer(value, other) : undefined//由customizer计算比较结果
  return result === undefined ? baseIsEqual(value, other, undefined, customizer) : !!result//若是customizer的结果是undefined,调用baseIsEqual处理
} export default isEqualWith
相关文章
相关标签/搜索