W3C home > Mailing lists > Public > www-dom@w3.org > July to September 2009

Re: Detecting and Creating Events

From: Jorge Chamorro <jorge@jorgechamorro.com>
Date: Sat, 29 Aug 2009 15:15:35 +0200
Message-Id: <F8D8B74A-7123-4377-9BFE-9457D72387E8@jorgechamorro.com>
To: www-dom@w3.org
On 28/08/2009, at 20:17, Garrett Smith wrote:
(...)
> - and so to follow this standard, a, plain old js object, with a -
> handleEvent - method is passed to - addEventListener -.
>
> And in an example, we can see that the DOM implementation does add the
> event listener and does call its - handleEvent - method when the
> document is clicked.
>
> Results:-
> Opera 10, Firefox 3.5, SeaMonkey/1.1.17, Chrome 2.0.172.39:
>
> PASS [object MouseEvent]
>
> Example:-
>
> <!doctype html>
> <html>
> <head>
> <title>Stuart!</title>
> </head>
> <body>
> <pre id="m">-</pre>
> <script type="text/javascript">
> document.addEventListener(
>  { toString: function(){return"click";}},
>  {handleEvent : function(ev){
>    document.getElementById("m").firstChild.data = "PASS "+ ev;}},
> true);
> </script>
> </body>
> </html>
>
> So, we can see that not only is it possible for an object to be passed
> to a DOM Implementation, but we already have a working example of this
> in browsers today.

<script type="text/javascript">
var arg1= { toString: function () { return "click"; } };
var arg2= { handleEvent : function (e) { alert(e); } };
document.addEventListener(arg1, arg2, true);
</script>

Your example shows, as Stewart said, the first argument being type- 
coerced by a call to (arg1).toString().

It shows as well a native JS object's (arg2) properties being read by  
(presumably) DOM-code.

However It does not show whether handleEvent is being type-coerced or  
not. If access to native objects' properties seems doable from within  
DOM-code, Stewart, in your opinion, what would prevent proper type- 
coercing ?

-- 
Jorge.
Received on Saturday, 29 August 2009 13:19:44 GMT

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