Coding task · JavaScript and TypeScript course · Module 8: Events and the DOM

Exercise: Event Bus

Implement a simple Event Bus with on, off, emit, and once methods for communication between application modules.

Task

The index.js file has an EventBus class with on(), off(), emit() and once() methods, as in the Event Bus lesson. Fill in the blanks: ___BLANK1___ is the array method that keeps every listener in off() except the removed one, and ___BLANK2___ is the EventBus method the one-time listener from once() uses to unsubscribe before calling the callback. emit() should call the listeners in the order they were added with the given arguments, off() should remove only the given listener, and a listener from once() should run only on the first emit().