Lodash - flowRight 方法



語法

_.flowRight([funcs])

此方法如同 _.flow,不同之處在於它建立一個函式來從右向左呼叫給定函式。

引數

  • [funcs] (...(Function|Function[])) − 待呼叫的函式。

輸出

  • (Function) − 返回新的複合函式。

示例

var _ = require('lodash');

function square(n) {
   return n * n;
}

var addAndSquare = _.flowRight([square, _.add]);
var result = addAndSquare(3, 2);
console.log(result);

tester.js 中儲存以上程式。執行以下命令來執行此程式。

命令

\>node tester.js

輸出

25
lodash_util.htm
廣告
© . All rights reserved.