- From: Jorge Chamorro <jorge@jorgechamorro.com>
- Date: Sat, 29 Aug 2009 15:15:35 +0200
- 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 UTC