Today we will tackle one of those challenges, naming things.
In JavaScript land, not too long ago, there was a reality many developers knew all too well called "callback hell" that has been helped greatly with the introduction of [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)
s but is still around because of one critical fact of JavaScript. It runs (by default) on the same thread as the UI of a page and must be done in between rendering. Thus, browsers and JavaScript engines have the "Event Loop".
- On the Web, we have the EventTarget class.
- And in Node, we have the [EventEmitter](https://nodejs.org/api/events.html#events_class_eventemitter] class.
Personally, I like EventTarget
because it explains that this is an object than can be the target of an event, whether or not the source of that event came from itself or not. It very quietly shows that dispatchEvent()
and CustomEvent
exist all without saying anything.
On the other hand I recently Jake Archibald on the HTTP 203 podcast that he prefers the EventEmitter
because is shows where the events are coming from.
The Web is backwards compatible if anything, but discourse is always fun to enlighten and help the future, so what are your thoughts? Which do you think is more effective at explaining its purpose?