Hacker News new | ask | show | jobs
by gorgoiler 98 days ago
I’ve been adding global listeners for click and keydown that call handleFoo(event) if event.target has a data-foo attribute.

The Invoker API seems like a neater way of handling the same pattern but I’m biased towards global event listeners because they work automatically on newly injected markup and they scale O(functionality) as opposed to per element listeners that scale O(elements). I’ll be the first to admit that the latter is more of an aesthetic choice rather than being based on any kind of performance statistics.

1 comments

O(depth) too, no? The events have to bubble up to the window before triggering your handler.