Should I always removeEventListener?

Let's say I add an event loadto the window as follows:

window.addEventListener("load",initialize);

Should I then remove the boot event listener from the window after the event fires? It only works once, but will it continue to listen after that?

It is quite simple:

function initialize(event_){
    /* Just by adding this line. */
    window.removeEventListener("load",initialize);
}

But is this what can actually affect the performance of my program? I just ask because the load event only fires once, so it would be wise if it just resolved itself. I have never heard of the most permissive listener, though ... Any thoughts?

Edit: Also, I'm not particularly interested in the "load" event, just in the general scenario, in which the listener continues to listen to the event, which fires only once.

+4
2

?

, , , .

, ?

DOM, . , load (. MDN ).

, ?

, . , initialize, ( , ) , .

+2

window.addEventListener('load', initialize, {once: true});

0

All Articles