<!-- should be equivalent to //

In IE, Firefox, Opera and Safari, the character sequence <!-- in  
javascript is a line comment, i.e. equivalent to //. ECMA 262 didn't  
define this. AFAICT ES4 doesn't define it, either. *Many* pages on the Web  
rely on this, so browsers cannot remove it for existing content.

Note that HTML cannot fix this, because <!-- is used in external js files  
in the wild, and HTML doesn't have a look-in there.

I note that this behavior is incompatible with E4X, where <!-- would be  
the start of an XML comment object. Unless I'm mistaken Firefox handles  
this incompatibility with the ;e4x=1 switch...

Also, it seems that Firefox and Safari sometimes treat --> as a line  
comment, too, but that IE and Opera don't.

Some demos:

    http://tc.labs.opera.com/ecmascript/html-comments/


Is this something that can be specced in ES4? Or is the intent to require  
UAs to have a switch such that they can disable the <!-- treatment for ES4  
scripts, and keep it for legacy scripts? (If the latter, ES3 still needs  
an update if this is going to be specced at all...)

Cheers,
-- 
Simon Pieters
Opera Software

Received on Monday, 22 October 2007 12:56:11 UTC