3 ms·
In JavaScript, const myEvent = 'myEvent', target = new EventTarget() target.on( myEvent, () => { console.log( "It's easy to introspect well-o
by soulofmischief 2y ago
In JavaScript,
const
myEvent = 'myEvent',
target = new EventTarget()
target.on( myEvent, () => {
console.log( "It's easy to introspect well-organized code." )
})
target.dispatchEvent( new Event( myEvent ))
- lmm 2y agoYeah, good luck remembering to do that up-front for every event handler. You missed one? Whoops, enjoy the information you wanted silently not being there when you need it.
- soulofmischief 2y agoRemembering to do what? Properly maintain a list of constants and enums to use throughout my application? That's not something I have to remember or forget, it's a simple habit that is as natural as importing and referencing a function. As a general rule, numbers and string literals should never be hardcoded. Internalizing this should be a base expectation of any high-performing team member.