4 ms·
JavaScript: Understanding CustomEvent and DispatchEvent
- russellbeattie 4y agoPretty sure you want to create a new event object new each time. I think it prevents cancellation or maybe event resetting. The article's example seems like it works, though. Who knows what sort of magic is going on inside the browser as this is a super common pattern - even half of MDNs examples use events this way. Maybe I'm just old school. In my brain I envision an event object as a sort of data closure around whatever just happened to cause the event, like the timestamp, activation details, etc. So you'd want to make a new one each time you dispatch it. Then again, maybe the browser modifies all that bit in the dispatchEvent function. I'll have to test. Anyone already know?