Lodash _.isMatchWith

2021-09-24 10:22 更新

_.isMatchWith(object, source, [customizer]) 

這個(gè)方法類似_.isMatch。 除了它接受一個(gè) customizer 定制比較的值。 如果 customizer 返回 undefined 將會比較處理方法代替。 customizer 會傳入5個(gè)參數(shù):(objValue, srcValue, index|key, object, source)。

添加版本

4.0.0

參數(shù)

  1. object (Object): 要檢查的對象。
  2. source (Object): 屬性值相匹配的對象。
  3. [customizer] (Function): 這個(gè)函數(shù)用來定制比較。

返回

(boolean): 如果object匹配,那么返回 true,否則返回 false。

例子

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


以上內(nèi)容是否對您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號
微信公眾號

編程獅公眾號