I meant that IE alert case indeed ... but yeah, you wrote better examples.

Nothing block me to create a function and remove some magic to the "on"
getter so that I can set directly the proxy there.

In few words mine was a proof of concept on how we could do it and how to
bring the right "this" through the second property access.

Rather than Object.prototype.on via define property ..

// horrible name, I know, just as example
Object.asEmitter = function asEmitter(o) {
  return Object.defineProperty(o, "on", {
    // everything else that happens in the original proof of concept
    // problem with variable "event" solved
  });
};

var o = Object.asEmitter(Object.create(null));
o.on.whatever.add(callback);
o.on.whatever({type: "whatever"});

br

On Sat, Oct 15, 2011 at 8:19 PM, David Bruant <bruan...@gmail.com> wrote:

> Le 15/10/2011 19:52, Andrea Giammarchi a écrit :
> > naaa, "event" is just a placeholder ... most likely is gonna be
> >
> > var event = "@__event__" + Math.random();
> Or rather a private name (when this is implemented)?
> Or with some WeakMap trickeries?
>
> > and most likely that code should be on top with all other native
> > prototypes shims or improvements.
> >
> > the correct this is bound as expected, the click function will have
> > this === object indeed
> >
> > When I wrote any sort of object, i implicity meant any that inherits
> > from Object.prototype ... are other "objects" ? I don't think so ... I
> > would never do something like
> >
> > alert.on.alert(callback);
> Actually, in something else than old IE, 'alert' is a regular function
> and it's [[prototype]] chain is like:
> alert --> Function.prototype --> Object.prototype --> null
> So 'alert' should be fine actually.
>
> There are indeed other objects that you can create:
> ----
> var o1 = Object.create(null);
> var o2 = Object.create(o1);
> var o3 = Object.create(o2);
> var o4 = Object.create(o2); // both inherit from o2
> // etc.
> ----
> None of them contain Object.prototype in their prototype chain and I
> don't see any strong reason to prevent these objects from emitting events.
>
> > you know what I mean ;-)
> I do. Actually, one of my initial thought was to do something with
> Object.prototype but I stopped as soon as I remembered that some objects
> may not inherit from it.
>
> > br
> >
> > P.S. I just pressed reply but I think I removed your text through
> > selection ... apologies
> No worries :-)
>
> David
>
_______________________________________________
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to