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