Loading challenge...
Preparing the challenge details...
Loading challenge...
Preparing the challenge details...
Implement a pub/sub EventEmitter class with on, off, emit, and once — the pattern behind Node's events module.
An EventEmitter is the publish/subscribe pattern: register listeners with on, remove them with off, fire them with emit, and register one-time listeners with once. Two details interviewers watch for: iterating over a copy of the listener array in emit (so a self-removing listener doesn't corrupt the loop), and the once wrapper that unregisters itself by reference.
Goal: Implement all four EventEmitter methods. Pay attention to the .slice() in emit and the wrapper in once.
Continue learning with these related challenges
Implement your own Promise.all polyfill to understand how concurrent Promise handling works under the hood.
Implement a Function.prototype.call polyfill from scratch. Master JavaScript this binding, execution context, primitive boxing, and safe property assignment techniques.
Implement Array.prototype.reduce from scratch, including the tricky no-initial-value path and the empty-array error case.
Implement your own Promise.all polyfill to understand how concurrent Promise handling works under the hood.
Implement a Function.prototype.call polyfill from scratch. Master JavaScript this binding, execution context, primitive boxing, and safe property assignment techniques.
Implement Array.prototype.reduce from scratch, including the tricky no-initial-value path and the empty-array error case.