Skip to content

on() ​

Attaches a listener function to an event, allowing it to be called when the event is emitted. This method is almost an alias of addListener(), but does not support the once parameter.

Example ​

typescript
instance.on("foo", () => {
  /* [...] */
});

Parameters ​

ParameterTypeDefaultDescription
eventstring | symbolThe event name. Expects an ESMitterEventName.
fnunknownThe function that will be called when the event is emitted.
contextunknownundefinedThe context to invoke the listener with.

Returns ​

TypeDescription
ESMitterThe ESMitter instance, allowing for method chaining.

once() ​

To attach a one-time listener, use once() instead.