W3C home > Mailing lists > Public > www-svg@w3.org > December 2005

SVGT 1.2: <handler> script scope and `this' object

From: Maciej Stachowiak <mjs@apple.com>
Date: Wed, 28 Dec 2005 04:38:09 -0700
Message-Id: <A46A34A4-4129-4CD3-8E81-CD0EA2BF4E69@apple.com>
To: www-svg@w3c.org

The SVG 1.2 Tiny spec says:

"Event listeners attached through event attributes and handler  
elements are also evaluated using the global scope of the document in  
which they are defined."

This has a few issues:

1) Contradiction: the description of the <handler> element says that  
the contents of the handler behave as if they are the contents of a  
new function body, but functions in ECMAScript have their own scope  
and do not execute at global scope. This makes a difference for  
example in the processing of "var" declarations. At global scope they  
would declare global variables, at function scope they would declare  
variables local to the function. Please resolve the contradiction.

2) Event listeners attached via addEventListener or via event handler  
attributes run with this "this" object bound to the EventTarget to  
which they are attached (the "observer" in XML Events parlance). This  
is extremely useful behavior. The SVGT 1.2 spec does not make clear  
whether this happens or not. It doesn't say whether the function  
created from a <handler> body is attached with addEventListener, or  
acts as if it had been. Please specify that the function object  
created from a <handler> acts as if attached in this way.

3) Event listeners attached via event handler attributes (at least in  
html) run with the element to which they are attached (the observer,  
effectively) pushed into the scope chain. This is extremely useful  
and makes it easy to write quick inline scripts. SVGT 1.2 should  
specify this behavior for <handler> as well for ease of use and  

Received on Wednesday, 28 December 2005 12:10:55 UTC

This archive was generated by hypermail 2.3.1 : Wednesday, 8 March 2017 09:47:05 UTC