Post

Do delegates feel natural in JavaScript? class Installer { constructor(delegate) { this.delegate = delegate } install() { if (this.delegate) { const event = new Event() this.delegate?.beforeInstall(event) if (event.defaultPrevented) return } } }

or should this always be handled by EventEmitter instead? class Installer extends EventEmitter { install() { const event = new Event() this.emit('before-install', event) if (event.defaultPrevented) return } }

TIL. I wonder if this would find traction in both UI and backend code.

0 reposts0 likes