Versions Compared
compared with
Key
- This line was added.
- This line was removed.
- Formatting was changed.
Comment:
Migrated to Confluence 5.3
Excerpt |
---|
Create a new function based on an existing function but with some parameters pre-defined. |
Syntax
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
// create new function based on existing one with one or more pre-defined arguments var fNewnewFn = fExistingexistingFn.uCurry(cArgscurry(args...); // use the new function, optionally specifying additional arguments fNew(args var result = newFn(extraArgs...); |
Parameters / Functions
Parameter / Function | Type | Mandatory | Description | Util.js version | fExistingAPI Version | |
---|---|---|---|---|---|---|
existingFn | Function | The original function | 1.0.5 | cArgs|||
args... | One or more arguments | One or more arguments that will be passed in to fExistingexistingFn when you access it via fNew | 0.5 | argsnewFn 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 (based on requirements of fExisting) pass in remaining arguments when calling fNew newFn | 1.0.5 |
Return value
Value | Type | Description | Util.js version | <fNew>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.5 | |
<fExisting><existingFn> | Function | If you do not specify cArgs then the existing function will be returned. | 1.0.5 | |
<result> | Variant | The result of running newFn() | 1.0 |
Example
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
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) |
Div | ||||||
---|---|---|---|---|---|---|
| ||||||
Availability
Requires:
|
Div | ||||
---|---|---|---|---|
| ||||
AvailabilityThis feature requires: Util.js v0.5 and above.ContentsJump to:
|
Div | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
| ||||||||||
Function ManipulationTopics:
|
Div | ||
---|---|---|
| ||
SeealsoAlsoRelated articles: pages:
|