Closed
Bug 48962
Opened 25 years ago
Closed 25 years ago
JavaScript functions declared in comments don't work
Categories
(Core :: JavaScript Engine, defect, P3)
Tracking
()
People
(Reporter: john, Assigned: rogerl)
References
()
Details
Attachments
(1 file)
271 bytes,
text/html
|
Details |
User-Agent: Mozilla/5.0 (Windows; U; WinNT4.0; en-US; m18) Gecko/20000814
BuildID: 2000081404
When you declare a JavaScript function in script comments, like so:
<SCRIPT>
<!--
function x() { }
-->
</SCRIPT>
Then the function will not be accessible. If you drop the comments (<!-- and
-->) then the function becomes accessible.
Strangely, JavaScript inside comments appears to actually be interpreted, so
it's probably not entirely the parser's fault. For example, if you place this
inside the head:
<SCRIPT>
<!--
alert("Yay");
-->
</SCRIPT>
Then the alert occurs. It is only function definitions that seem to be affected.
Reporter | ||
Comment 1•25 years ago
|
||
Reporter | ||
Comment 2•25 years ago
|
||
I wanted to note how the testcase worked: "Try Y" works because it is not in
comments, "Try X" does not work because it is.
Comment 3•25 years ago
|
||
what about if you close the html comment with a leading javascript comment:
//-->
Reporter | ||
Comment 4•25 years ago
|
||
Thanks! That works great! Now it is narrowed down to the end comment being the
culprit: still, only function declarations do not happen when this occurs.
alerts and such work fine.
More info: when functions are combined with an alert() in the block, the alert
does not happen. The order of the two does not matter (alert vs. functions or
functions vs. alert).
IE5 and Netscape 4.73 work fine (the testcase doesn't work on Netscape without
tweaking, but the comment thing does) and I know for a fact that during the M17
cycle this worked fine in Mozilla too. It is definitely a recent change.
Comment 5•25 years ago
|
||
John, thank you for reporting this; you are absolutely correct.
I have to mark this one as a duplicate of bug 31255, though ...
This is a long story, but you will notice the most recent attachment
to bug 31255 is the same testcase that you have discovered.
To see it quickly, you can use this URL in NN4.7:
view-source:http://bugzilla.mozilla.org/showattachment.cgi?attach_id=7675
*** This bug has been marked as a duplicate of 31255 ***
Status: UNCONFIRMED → RESOLVED
Closed: 25 years ago
Resolution: --- → DUPLICATE
You need to log in
before you can comment on or make changes to this bug.
Description
•