Skip to content

conforms

js
_.conforms(source)

创建一个使用给定对象的相应属性值调用 source 的谓词属性的函数,如果所有谓词都返回真值,则返回 true,否则返回 false

¥Creates a function that invokes the predicate properties of source with the corresponding property values of a given object, returning true if all predicates return truthy, else false.

注意:创建的函数相当于部分应用了 source_.conformsTo

¥Note: The created function is equivalent to _.conformsTo with source partially applied.

新增于

¥Since

4.0.0

参数

¥Arguments

  1. source (对象):要遵循的属性谓词的对象。

    ¥source (Object): The object of property predicates to conform to.

返回

¥Returns

(函数):返回新的 spec 函数。

¥(Function): Returns the new spec function.

示例

¥Example

js
var objects = [
  { 'a': 2, 'b': 1 },
  { 'a': 1, 'b': 2 }
];

_.filter(objects, _.conforms({ 'b': function(n) { return n > 1; } }));
// => [{ 'a': 1, 'b': 2 }]

Lodash v4.17 中文网 - 粤ICP备13048890号