Skip to content

Home > @idealeap/pipeline > EventEmitter > on

EventEmitter.on() method

Subscribes a listener function to a specified event.

Signature:

typescript
on(event: string, listener: (...args: any[]) => void): void;
on(event: string, listener: (...args: any[]) => void): void;

Parameters

ParameterTypeDescription
eventstringThe name of the event to which the listener should be subscribed.
listener(...args: any[]) => voidThe callback function that will be invoked when the event is emitted.

Returns:

void

Example

js
const emitter = new EventEmitter();
emitter.on('data', (data) => console.log(data));
const emitter = new EventEmitter();
emitter.on('data', (data) => console.log(data));

Released under the MIT License.