Lodash - negate 方法

语法

_.negate(predicate)

创建一个否定谓词 func 的结果的函数。使用创建的函数的 this 绑定和参数调用 func 谓词。

参数

  • predicate (Function) − 要否定的谓词。

输出

  • (Function) − 返回新的否定函数。

示例

var _ = require('lodash');

function isEven(n) {
   return n % 2 == 0;
}
 
console.log(_.filter([1, 2, 3, 4, 5, 6], _.negate(isEven)));

将上述程序保存在tester.js中。运行以下命令执行该程序。

命令

\>node tester.js

输出

[ 1, 3, 5 ]

lodash_function.html