Dentro il libro Javascript The definitive guide, è riportato un esempio che non capisco
Codice PHP:
// Register the function f to run when the document finishes loading.
// If the document has already loaded, run it asynchronously ASAP.
function onLoad(f) {
if (onLoad.loaded) // If document is already loaded
window.setTimeout(f, 0); // Queue f to be run as soon as possible
else if (window.addEventListener) // Standard event registration method
window.addEventListener("load", f, false);
else if (window.attachEvent) // IE8 and earlier use this instead
window.attachEvent("onload", f);
}
// Start by setting a flag that indicates that the document is not loaded yet.
onLoad.loaded = false;
// And register a function to set the flag when the document does load.
onLoad(function() { onLoad.loaded = true; });
è in particolare l'ultima riga che non capisco cosa dovrebbe significare...
Ad occhio direi che è una sorta di sintassi abbreviata per l'"addEventListener" dell'onload, ma facendo delle prove non è così difatti non accade assolutamente nulla al caricamento della pagina.
Potete darmi delle delucidazioni? thx