

It's time for a native EventEmitter - ricardobeat
http://ricardo.cc/2012/08/09/Its-time-for-a-native-EventEmitter.html

======
mistercow
Ooh, yes please, and can we also please have every browser provide slightly
different behavior, preferably through prefixed APIs? That way, we can have a
dozen _new_ libraries that smooth over the differences until Ecma has a chance
to standardize it in 2015 or so! What fun!

------
majke
Great, let's write one EventEmitter and make everyone else use that. What?

The problem is different - there is no single package manager in the browser
world that has taken off.

BTW. In the browser the native and well documented way of dealing with
callbacks is by using the EventTarget API:

[http://www.w3.org/TR/DOM-Level-2-Events/events#Events-
EventT...](http://www.w3.org/TR/DOM-Level-2-Events/events#Events-EventTarget)

~~~
deno
> BTW. In the browser the native and well documented way of dealing with
> callbacks is by using the EventTarget API

Closure Library uses EventTarget for their event handling system[1], thus
making it work exactly the same for browser events and custom events. YUI 3
takes similar approach, but instead they use their own API, however also based
on DOM events model.

[1] [https://closure-
library.googlecode.com/svn/docs/class_goog_e...](https://closure-
library.googlecode.com/svn/docs/class_goog_events_EventTarget.html)

~~~
ricardobeat
You mean they implement their own event emitter following the EventTarget spec
:)

~~~
deno
I meant to write EventTarget _API._ Yep.

However, the implication is that it’s based on the DOM event model. So, for
example, you have three stage processing: 1) capture phase, 2) target phase,
and 3) bubble phase. YUI 3 has its own API, but they still follow that model.
This is a bit stronger contract than just your generic ‘EventEmitter,’ which
only implies a simple observer model.

------
dasmoth
As an occasional Javascripter, I've gone looking for this several times, and
each time been bemused to discover it isn't there (probably just as an
instantiatable EventTarget).

Better package management might help, but some things are fundamental enough
that they belong in the core library. I'm pretty certain this is one of them.

------
Zecc
Yes, I've thought this for quite some time.

Heh, I just wrote a "me too" post. :J

