Object-Oriented / Patterns
Custom Event Emitter
mediumJS SpecificJS / TS5 tests
Problem Statement
Design an `EventEmitter` class with `subscribe(eventName, callback)` and `emit(eventName, args)` methods. `subscribe` should return an unsubscribe handle object with an `unsubscribe()` method.
Examples
Example:
const emitter = new EventEmitter();
const sub = emitter.subscribe('onClick', (x) => console.log(x));
emitter.emit('onClick', [42]); // prints 42
sub.unsubscribe();JavaScript & TypeScript starter code included
Run this as a live interviewPractice solo
5 test cases. No second person needed.