Create a new function based on an existing function but with some parameters pre-defined.
Syntax
// create new function based on existing one with one or more pre-defined arguments
var newFn = existingFn.curry(args...);
// use the new function, optionally specifying additional arguments
var result = newFn(extraArgs...);
Parameters / Functions
Parameter / Function
Type
Mandatory
Description
API Version
existingFn
Function
The original function
1.0
args...
One or more arguments
One or more arguments that will be passed in to existingFn when you access it via newFn
If you don't specify any arguments, .curry() will just return existingFn as there's no point in creating a curried function.
1.0
extraArgs...
Additional arguments
Optionally pass in remaining arguments when calling newFn
1.0
Return value
Value
Type
Description
API Version
<newFn>
Function
A new function which will automatically set the cArgs arguments for fExisting and then append any additional arguments passed in to fNew.
1.0
<existingFn>
Function
If you do not specify cArgs then the existing function will be returned.
1.0
<result>
Variant
The result of running newFn()
1.0
Example
Predefining first param to a number...
function add(a, b) {
return a + b;
}
var Add5To = add.curry(5); // parameter "a" is pre-defined with value 5
Add5To(10); // 15 (parameter "a" already set to 5, "b" set to 10)