loading...

Naming things: EventTarget or EventEmitter?

nektro profile image Meghan Denny ・1 min read

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".

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?

Posted on by:

nektro profile

Meghan Denny

@nektro

23. Local trans witch who prefers to do magic with a keyboard. she/her. Currently hacking away at making the Web less centralized.

Discussion

markdown guide