negate source npm

_.negate(predicate)

创建一个对 func 结果 取反的函数。 用 predicate 对 func 检查的时候,this 绑定到创建的函数,并传入对应参数。

参数

  1. predicate (Function)

    需要对结果取反的函数

返回值 (Function)

返回一个新函数

示例

function isEven(n) {
  return n % 2 == 0;
}

_.filter([1, 2, 3, 4, 5, 6], _.negate(isEven));
// => [1, 3, 5]