Classes
Methods
(inner) apply(target, thisArg, args) → {Promise}
- Source:
This is a trap for when a function gets called (remember this gets used for
then
/
catch
/finally
); it processes the result using the oringinal function and
since promise methods return a promise, instead of returning the original result,
it returns an extended version of it.
Parameters:
Name | Type | Description |
---|---|---|
target |
function | The original function. |
thisArg |
Promise | The promise the function belongs to. |
args |
Array | The list of arguments sent to the trap. |
Returns:
- Type
- Promise
(inner) extendPromise(promise, properties) → {Proxy.<Promise>}
- Source:
- Tutorials:
Extends a Promise
by injecting custom properties using a Proxy
. The
custom properties will be available on the promise chain no matter how many then
s,
catch
s or finally
s are added.
Parameters:
Name | Type | Description |
---|---|---|
promise |
Promise | The promise to extend. |
properties |
Object | A dictionary of custom properties to inject in the promise chain. |
Throws:
-
-
If
properties
is not an object or if it doesn't have any properties. - Type
- Error
-
Returns:
(inner) get(target, name) → {*}
- Source:
This is a trap for when something is trying to read/access a property for the
promise.
The function first validates if it's one of the functions
(then
/catch
/finally
) in order to return a proxied function; then, if it's
another function (one that doesn't return another promise), it just calls the
original; finally, before doing a fallback to the original promise, it checks if
it's one of the custom properties that exented the promise.
Parameters:
Name | Type | Description |
---|---|---|
target |
Promise | The original promise. |
name |
string | The name of the property. |
Returns:
- Type
- *