isMatch

5.22 isMatch

5.22.1 语法

_.isMatch(object, properties)

5.22.2 说明

如果object包括properties,返回true

5.22.3 代码示例

示例一:基本用法

var stooge = {name: 'moe', age: 32};

_.isMatch(stooge, {age: 32}); //=> true
_.isMatch(object, {age: 36 }); //=> false

示例二:嵌套之后不匹配

var stooge = {user : {name: 'moe', age: 32}};
_.isMatch(stooge, {age: 32}); //=> flase

示例三:properties可多个

var stooge = {name: 'moe', age: 32};
_.isMatch(stooge, {name: 'moe', age: 32}); //=> true

示例四:请使用在object上,否则结果令人意外

//数组的时候
_.isMatch([1, 2, 3], 4); // 意外 => true
_.contains([1, 2, 3], 4); //=> false

//字符串
_.isMatch('123', '4'); // 意外 => true
_.contains('123', '4'); //=> false

5.22.4 isMatch怪异的null

_.isMatch(null, {}); // => true
_.isMatch(null, ''); // => true
_.isMatch(null); // => true