Rick Waldron (2013-07-10T22:57:57.000Z)
domenic at domenicdenicola.com (2013-07-13T01:57:56.567Z)
I don't want any of this on my `Object` objects. Not all objects represent something that can or should emit/publish/trigger/broadcast. For example... ```js class Light { constructor() { // initialize Light control instance } on() { // send bits to turn Light on } off() { // send bits to turn Light off } } ``` So what happens now? All of my `Led` instances have `emit`, `trigger`, `once` and `boundTo` methods that are actually useless now. No thanks. I also don't want `Object.prototype.*` and `Object.*` to suffer the same way that the [[Global]] (`window`) object in browsers has suffered. Give a hoot, don't pollute. Post ES6 world makes creating emitter objects trivial—so why not a blessed standard lib module that can be imported and used to extend a class declaration? ```js import { Emitter } from "@event"; class Foo extends Emitter {} ``` Easy. More inline... On Wed, Jul 10, 2013 at 12:46 PM, Matthew Robb <matthewwrobb at gmail.com>wrote: > You can do chainability at object define time with the sugar form: > > ```js > var obj = { > on type1(){}, > on type2(){}, > on type3(){} > } > ``` This is the dark days of DOM element properties as event handlers: ```js elem.onclick... ``` Assigning to this paves over the previous assignment, leaving no way to have multiple handlers registered for the same event type. On Wed, Jul 10, 2013 at 12:41 PM, Andrea Giammarchi <andrea.giammarchi at gmail.com> wrote: > my implementation works already with `DOM` nodes and browser environment, including `window`. > I've also already written an `EventTarget` mixin object but in my case I'd use that via `Object.mixin(Object.prototype, EventTarget);` 'cause almost every object I use in my logic should be observed or should emit something to some other object. Standard lib approach (a la node) works today and tomorrow. > I find the `Object.addEventListener(obj, "type", handler)` approach very boring for the simple reason that it does not make sense to use chainability there, another de-facto thing when it comes to events. It's also (subjectively) hideous. > ```javascript > // current eddy.js status > var obj = {} > .on(type1, handler1) > .on(type2, handler2) > .on(type3, handler3) > ; > ``` That's great for your use case, but I would never want this by default.