Skip to content

addListener()

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

Parameters

ParameterTypeDefaultDescription
eventstring | symbolThe event name. Expects an ESMitterEventName.
fnunknownThe function that will be called then the event is emitted.
contextunknownundefinedThe context to invoke the listener with.
oncebooleanfalseSpecify if the listener is a one-time listener.

on()

The on() method is almost an alias of addListener(), the only exception being the missing once parameter. For this, use once() instead.