negate
源码
/**
* 创建一个针对断言函数 func 结果取反的函数。 func 断言函数被调用的时候,this 绑定到创建的函数,并传入对应参数。
*
* @since 3.0.0
* @category Function
* @param {Function} predicate 需要对结果取反的函数。
* @returns {Function} 返回一个新的取反函数。
*/
function negate(predicate) {
if (typeof predicate != 'function') {
throw new TypeError('Expected a function');
}
return function(...args) {
return !predicate.apply(this, args);
};
}原理
相关链接
Last updated