主题
curry
js
_.curry(func, [arity=func.length])
创建一个接受 func
参数的函数,如果至少提供了 arity
个参数,则调用 func
返回其结果,或者返回一个接受其余 func
个参数的函数,依此类推。如果 func.length
不够,可以指定 func
的参数。
¥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.
_.curry.placeholder
值在单片构建中默认为 _
,可用作提供的参数的占位符。
¥The _.curry.placeholder
value, which defaults to _
in monolithic builds, may be used as a placeholder for provided arguments.
注意:此方法不设置柯里化函数的 "length" 属性。
¥Note: This method doesn't set the "length" property of curried functions.
新增于
¥Since
2.0.0
参数
¥Arguments
func
(函数):要柯里化的函数。¥
func
(Function): The function to curry.[arity=func.length]
(数值):func
的元数。¥
[arity=func.length]
(number): The arity offunc
.
返回
¥Returns
(函数):返回新的柯里化函数。
¥(Function): Returns the new curried function.
示例
¥Example
js
var abc = function(a, b, c) {
return [a, b, c];
};
var curried = _.curry(abc);
curried(1)(2)(3);
// => [1, 2, 3]
curried(1, 2)(3);
// => [1, 2, 3]
curried(1, 2, 3);
// => [1, 2, 3]
// Curried with placeholders.
curried(1)(_, 3)(2);
// => [1, 2, 3]