Skip to content

Events.on method

Events › on

Official

Add an event listener.

Signature:

on(name: string, callback: (...data: unknown[]) => unknown, ctx?: unknown): EventRef

Parameters:

Parameter Type Description
name string The name of the event.
callback (...data: unknown[]) => unknown The callback to call when the event is triggered.
ctx? unknown The context passed as this to the callback.

Returns: EventRefA reference to the event listener.

Since: 0.9.7

Example:

events.on('my-event', (arg1, arg2) => {
console.log(arg1, arg2);
});