Properties:
Name | Type | Description | ||||||
---|---|---|---|---|---|---|---|---|
aidsIn |
function | The Functionw class Properties
|
- Source:
Methods
(static) capArgs(fn, capopt, contextopt) → {function}
Limits the number of arguments that can be used by a function.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
fn |
function | The function to cap the number of arguments on. |
||
cap |
number |
<optional> |
fn.length | The cap of the number of args. |
context |
Object |
<optional> |
null | The context to run the function on. |
- Source:
Returns:
The function with arguments capped.
- Type
- function
Example
function j(a,b,c) { return a + '+' + b + '+' + 'c' };
j = Function.capArgs(j, 2);
j(1,2,3); // '1+2+undefined'
(static) curry(fn, arityopt, contextopt) → {function}
Allows the function to be called many times, before executing.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
fn |
function | The function to curry. |
||
arity |
number |
<optional> |
fn.length | The number of arguments to execute it at. |
context |
Object |
<optional> |
null | The context to execute in. |
- Source:
Returns:
The curried function.
- Type
- function
Example
function j(a,b,c) { return [a,b,c] };
j = Function.curry(j);
j(1,2)(3); // [1,2,3]
j(1)(2,3); // [1,2,3]
j(1)(2)(3); // [1,2,3]
(static) flow(…functs) → {function}
Applies functions in order of the arguments passed to Function.flow
.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
functs |
function |
<repeatable> |
The functions to flow. Each function should return an array of arguments to pass to the next function, or a single value. |
- Source:
Returns:
The resulting built function.
- Type
- function
Example
function add(a,b) { return a + b };
function square(a) { return a ** 2};
addSquare = Function.flow(add, sqaure);
addSquare(1,2); // 9
(static) memoize(fn, contextopt) → {function}
Caches the result. Should only be used on pure functions, which return the same result for the same input.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
fn |
function | The function to cache. |
||
context |
Object |
<optional> |
null | The context to operate in. |
- Source:
Returns:
The resulting function.
- Type
- function
(static) once(fn, contextopt) → {function}
Restricts the execution of a function to one call. Note this does not change the original function.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
fn |
function | The function to limit. |
||
context |
Object |
<optional> |
null | The context to use. |
- Source:
Returns:
The restricted function.
- Type
- function
Example
function k(a) { return a };
k = Function.once(k);
k(3); // 3
k(4); // 4
(static) reArg(fn, indexes, contextopt) → {function}
Re-arranges the arguments to a function.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
fn |
function | The function to remap the arguments. |
||
indexes |
Array.<number> | Object.<number, number> | The way to map the arguments. |
||
context |
Object |
<optional> |
null | The context to set the |
- Source:
Returns:
The resulting re-mapped function!
- Type
- function
Example
function j(a,b,c) { return `${a}+${b}+${c}` };
j = Function.reArg(j, [2, 1, 0])
j(1,2,3); // '3+2+1'
(static) template(fn, contextopt, …BoundArgs) → {function}
Templates a function, enabling you to set static arguments and placeholders.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
fn |
function | The function to template. |
||
context |
Object |
<optional> |
null | The context to operate the function under. |
BoundArgs |
* |
<repeatable> |
The arguments to revert to static, use '_PH_' for placeholders. |
- Source:
Returns:
The resulting function.
- Type
- function
Example
function j(a,b,c) { return a + '+' + b + '+' + c };
j = Function.template(j, null, 3, '_PH_', 2);
j(4); // '3+4+2'
j(8); // '3+8+2'
(static) throttle(fn, time, contextopt) → {function}
Delayes the execution of a function. You call it with the normal arguments you would. If you don't wait until the timout expires, this also works as a debounce method.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
fn |
function | The function to throttle. |
||
time |
number | The delay to execute the function after. |
||
context |
Object |
<optional> |
null | What context to execute under. |
- Source:
Returns:
The throttled function.
- Type
- function
Type Definitions
ModifiedFunction()
Used to denote that the function has been modified, and may not be a pure function.
- Source: