before()
import { before } from "@fed1/jsos";
A JSFunction
that defines a qualified method for the before
slot of a
multimethod.
A before method is called right before any primary methods are executed. It does not influence the inputs or outputs of the multimethod, but it can be used like an event listener to plug-in additional functionality like logging.
Usage
before(multimethod, comparators, fn)
Parameters
# | Parameter | Required? | Type | Default |
---|---|---|---|---|
1 | multimethod | yes | TGeneric | |
2 | comparators | yes | JSArray | |
3 | fn | yes | JSFunction |
1. multimethod
The multimethod to which an before
method shall be added.
2. comparators
An array of comparators (types) to which this method applies.
3. fn
The method body supplied as a callback function.
Return value
The JSFunction
that was used as the method body. Usually, you can just discard
this value. It becomes useful when you want to remove the added method later on
at runtime for which you need to keep a reference of the function.
Version History
Feature | Since version |
---|---|
before() | 1.0 |