Creates an instance of the class 'EventEmitter'.
Internal object that stores events.
Alias of the method 'on', which can be used to register an event listener.
Register a listener for the specified event.
Name of the event.
The function to be called when an event occurs.
Determines whether to output console logs.
Alias of the 'off' method, which can be used to remove a listener for a specified event.
Removes the listener for the specified event.
Name of the event.
Listener function to remove.
Removes all listeners for the specified event. Omitting the event name removes the listener of all events.
Optional
event: stringName of the event, which can be omitted.
function onQux(data) {
console.log ('qux event:', data);
}
function anotherOnQux(data) {
console.log('another qux 이벤트:', data);
}
emitter.on('qux', onQux);
emitter.on('qux', anotherOnQux);
emitter.emit('qux', { key: 'value' }); // "qux 이벤트: { key: 'value' }", "another qux 이벤트: { key: 'value' }"
emitter.removeAllListeners('qux');
emitter.emit ('qux', {key: 'value'}); // Nothing happens
The 'EventEmitter' class provides the ability to manage event listeners and issue events. This class works similarly to Node.js' 'EventEmitter' and is designed for use in browser environments.