Closed Bug 119072 Opened 23 years ago Closed 23 years ago

JavaScript functions in second parameter of addEventListener are ran during parsing,before listener is called

Categories

(Core :: DOM: Events, defect)

x86
Windows 98
defect
Not set
normal

Tracking

()

VERIFIED INVALID

People

(Reporter: vladimire, Assigned: joki)

Details

Attachments

(1 file)

If the second parameter of addEventListener() is an actual function call, this
function is called during the parsing of the script, not when the event occurs.

Basicly if you have document.addEventListener("load",test(),0) in the HEAD
The function test is going to be executed before the BODY is even displayed.

The correct behaviour would be to generate some sort of a javascript error.

this occurs on 2002-01-07-03-trunk build on windows 98
The testcase script looks like this:

function test(e)
{
 alert("This should never be displayed because the function is never called");
}
document.addEventLister("neveroccurringevent",test(),0);


This event never occurs, even though the function test() is executed
This bug is invalid.

If you want to add the function |test| as an event listener, do:

  document.addEventLister("neveroccurringevent", test, 0);

that will do just that, if you do what your testcase does:

  document.addEventLister("neveroccurringevent", test(), 0);

mozilla will try to add the return value of calling the function test() as the
event listener, not the function test itself. Big difference. Mozilla does
exactly what you're asking it to do here, there is no bug shown by this testcase.

Marking INVALID.
Status: NEW → RESOLVED
Closed: 23 years ago
Resolution: --- → INVALID
ok
Status: RESOLVED → VERIFIED
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: