Lodash curry method
语法
_.curry(func, [arity=func.length])
Creates a function that accepts arguments of func and either invokes func returning its result, if at least arity number of arguments have been provided, or returns a function that accepts the remaining func arguments, and so on. The arity of func may be specified if func.length is not sufficient.
参数
func (Function) − The function to curry.
[arity=func.length] (number) − The arity of func.
输出
(Function) − Returns the new curried function.
实例
var _ = require('lodash');
var getArray = function(a, b, c) {
return [a, b, c];
};
var curried = _.curry(getArray);
console.log(curried(1)(2)(3));
console.log(curried(1, 2)(3));
console.log(curried(1, 2, 3));
Save the above program in
tester.js. Run the following command to execute this program.
Command
输出
[ 1, 2, 3 ]
[ 1, 2, 3 ]
[ 1, 2, 3 ]