Re: ACTION-70: Define the scope chain of onFoo events reference issue-1

Jim Ley wrote:
> 
> "Maciej Stachowiak" <mjs@apple.com>
>>> 1) Event listeners can not (and I also believe should not) be  
>>> capable of changing by modification of element attributes
>>
>> With the following test case, Safari, Firefox and Opera respect the  
>> DOM change and reflect it with a changed event handler:
> 
> I believe this is inconsistent behaviour, and should be changed:
> 
> <script id=chicken>
> function chicken() { alert(1); }
> </script>
> 
> and
> 
> document.getElementById('chicken').firstChild.nodeValue="function 
> chicken() { alert(2); }"
> 
> does not result in a change to the script, so it is unclear to me why 
> changing an attribute should be reflected in script.

The difference is that the <script> element is only evaluated once, so 
even if you change the contents of the node it does not matter since the 
element is never executed again.

At least in mozilla you can actually modify the contents of a <script> 
and it will have effect, as long as you do it before the <script> is 
executed.

There are two opportunities to do that. Either you can change the 
contents before the script is inserted into the document when you create 
the script using createElement.

Or you can change the contents of the script if the script has a src 
attribute that fails to load, but you change the contents before the 
load has failed. This is of course not a very useful thing to do, but it 
works.

I can see your point that it feels illogical that your example does not 
update the chicken function. However consider an example like:

<script id=chicken>
a = 1;
</script>

document.getElementById('chicken').firstChild.nodeValue="b = 2";

should that set 'b' to 2? What about undoing 'a = 1'? Obviously you 
can't "unrun" a previously run javascript, so for that reason we in 
mozilla decided that a normal <script> element only ever runs once and 
so there is no debate that anything should ever be "unrun".

When I say 'normal' above I mean <script> elements that aren't 
eventhandlers. Since eventhandlers run every time the event is fired I 
would argue that changes to them should take effect once the event fires.

> Similarly with XML 
> event handlers and changing the content - currently they do not get 
> changed.

That sounds like a bug to me and something that should be fixed in the 
implementation.

/ Jonas

Received on Wednesday, 15 March 2006 00:34:55 UTC