...
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
// create new function based on existing one with one or more pre-defined arguments
var fNew = fExisting.uCurry(cArgs);
// use the new function, optionally specifying additional arguments
fNew(args); |
Where fExisting is any existing function.
...
Parameters / Functions
Parameter / Function | Type | Mandatory | Description | Util.js version |
---|---|---|---|---|
fExisting | Function | The original function | 0.5 | |
cArgs | One or more arguments | One or more arguments that will be passed in to fExisting when you access it via fNew | 0.5 | |
args | Additional arguments | Optionally (based on requirements of fExisting) pass in remaining arguments when calling fNew | 0.5 |
Return value
Value | Type | Description | Util.js version |
---|---|---|---|
<fNew> | Function | A new function which will automatically set the cArgs arguments for fExisting and then append any additional arguments passed in to fNew. | 0.5 |
<fExisting> | Function | If you do not specify cArgs then the existing function will be returned. | 0.5 |
...
A better example is shown in in the Object.uAddProperty() example using using a curried allianceExistsBetween() function.
See also
- uCompose – Function.uCompose() – create a new function by merging two existing functions
- Curry – I based my uCurry function on code samples from this blog.