In this example, we create a subclass of EventEmitter called MyEmitter. We then create an instance of MyEmitter called myEmitter.
We define three events: 'event1', 'event2', and 'event3'. Each event is associated with a corresponding callback function that logs a message when the event is emitted.
We use the on() method to register the 'event1' and 'event2' events, and the once() method to register the 'event3' event. The on() method allows multiple callbacks to be registered for an event, while the once() method only allows a single callback to be registered, and it automatically unregisters the callback after it is triggered once.
We use setTimeout() to emit the events after a certain delay. We emit 'event1' after 1 second, 'event2' after 2 seconds, and 'event3' after 3 seconds.
When you execute this code, you should see the following output: