Sam@samuelmaddock.com26 Nov 2024Do 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 } } }1
Sam@samuelmaddock.com26 Nov 2024or 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 } }1
Sam@samuelmaddock.comTIL. I wonder if this would find traction in both UI and backend code.26/11/24, 7:29 pm·0 reposts·0 likes
Tim Fish@timfish.dev26 Nov 2024If it makes it to stage 3 it'll get included in all the js runtimes so I guess it would then become pretty universal