Underscore.js是一個JavaScript庫,它提供了許多有用的函數,即使不使用任何內置對象,它們也可以以很大的方式幫助編程,例如映射,過濾器,調用等。
_.negate()函數是JavaScript的Underscore.js庫中的內置函數,用於查找聲明的謂詞函數的新否定版本。
用法:
_.negate(predicate)
參數:它接受以下指定的單個參數:
- predicate:它是陳述的謂詞函數。
返回值:此方法返回所聲明謂詞函數的新否定版本。
範例1:
<!DOCTYPE html>
<html>
<head>
<script src=
"https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.9.1/underscore-min.js">
</script>
</head>
<body>
<script>
var isNaN = _.negate(Boolean);
console.log(_.find(
[3, -11, undefined, 41, 0], isNaN));
</script>
</body>
</html>
輸出:
undefined
範例2:
<!DOCTYPE html>
<html>
<head>
<script src=
"https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.9.1/underscore-min.js">
</script>
</head>
<body>
<script>
function isCSportal(character) {
return character === "GeeksforGeeks";
}
var isNotCSportal = _.negate(isCSportal);
console.log(isNotCSportal("GeeksforGeeks"));
console.log(isNotCSportal("GfG"));
</script>
</body>
</html>
輸出:
false true
參考:https://underscorejs.org/#negate
相關用法
- Lodash _.negate()用法及代碼示例
- PHP imagecreatetruecolor()用法及代碼示例
- p5.js year()用法及代碼示例
- d3.js d3.utcTuesdays()用法及代碼示例
- PHP ImagickDraw getTextAlignment()用法及代碼示例
- PHP Ds\Sequence last()用法及代碼示例
- PHP array_udiff_uassoc()用法及代碼示例
- PHP geoip_continent_code_by_name()用法及代碼示例
- d3.js d3.map.set()用法及代碼示例
- PHP GmagickPixel setcolor()用法及代碼示例
- PHP opendir()用法及代碼示例
- PHP cal_to_jd()用法及代碼示例
- d3.js d3.bisectLeft()用法及代碼示例
- PHP stream_get_transports()用法及代碼示例
注:本文由純淨天空篩選整理自nidhi1352singh大神的英文原創作品 Underscore.js _.negate() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。