_.compose()函數用於返回函數列表的組成。函數列表返回以下函數的值。
用法:
_.compose(*functions)
參數:該函數接受如上所述和以下描述的單個參數:
- functions:它包含要執行的函數列表。
返回值:它返回函數列表的組成。
以下示例說明了Underscore.js中的_.compose()函數:
範例1:
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src=
"https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.9.1/underscore-min.js">
</script>
</head>
<body>
<script type="text/javascript">
var fun1 = function (addString) {
return "Welcome to " + addString;
};
var fun2 = function (GFG) {
return GFG;
};
var str = _.compose(fun1, fun2);
console.log(str('GeeksforGeeks'));
</script>
</body>
</html>
輸出:
範例2:
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src=
"https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.9.1/underscore-min.js">
</script>
</head>
<body>
<script type="text/javascript">
var fun1 = function (str1) {
return 'Welcome' + str1 +
'\nA computer science portal';
};
var fun2 = function (str2) {
return ' to ' + str2.toLowerCase();
};
var str = _.compose(fun1, fun2);
console.log(str('GEEKSFORGEEKS'));
</script>
</body>
</html>
輸出:
相關用法
- 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()用法及代碼示例
注:本文由純淨天空篩選整理自AshokJaiswal大神的英文原創作品 Underscore.js | _.compose() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。