W3C home > Mailing lists > Public > www-dom@w3.org > January to March 2012

Re: [DOM4] EventTarget as first class citizen

From: Marcos Caceres <w3c@marcosc.com>
Date: Thu, 1 Mar 2012 00:01:35 +0000
To: Boris Zbarsky <bzbarsky@mit.edu>
Cc: www-dom@w3.org
Message-ID: <1F5EB74BBD79422D84C3FCB8A5FFFE85@marcosc.com>


On Wednesday, 29 February 2012 at 23:26, Boris Zbarsky wrote:

> On 2/29/12 6:00 PM, Marcos Caceres wrote:
> > So I would have expected Node's __proto__ to be "EventTarget". But it is not…
>  
> Yes, because that part of the spec is not implemented yet.

Yes, I can see both Chrome and Opera implement it in the same way. I tried to see it in FF, but I don't understand how to use the new "Web Console" (tried console.log(), but no joy :( ). I'm going to assume it is the same.  

I also had a very brief look at the DOM 2 and 3 specs, to get a bit of a legacy perspective, but that's just more confusing (they seem to assume some magic casting from Node to EventTarget… Java styles… which might explain why EventTarget is missing from the prototype chain in legacy implementations of DOM3). From DOM3 Core:

// example 1, without prepending the "+"
if (myNode.isSupported("Events", "3.0")) {
    EventTarget evt = (EventTarget) myNode;
    // ...
}


> The EventTarget methods would live on HTMLAnchorElement.prototype if   
> EventTarget were not on the proto chain, in your case.

> > Node somehow transparently/silently inherits EventTarget.
>  
>  
> No, it doesn't.
Sorry, I'm not sure what you mean (or I've missed something or worded it wrongly).  

Looking at the console in Opera, when I do dir(a) it is says "NodePrototype (+)" and addEventListener and friends are listed under there.  

Looking at Chrome, and doing console.dir(a), it's the same: Node has properties addEventListener and friends.    

Hence:
a.__proto__.__proto__.__proto__.__proto__.hasOwnProperty("addEventListener") === true



(all others return false)

interestingly, it's the same with Window… it is also supposed to inherit from EventTarget, but it doesn't (EventTarget's methods are just part of Window… so it's as if EventTarget doesn't exist at all for any Interface that inherits from it… creepy :)).  

--  
Marcos Caceres
http://datadriven.com.au
Received on Thursday, 1 March 2012 00:02:06 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Friday, 22 June 2012 06:14:09 GMT