In the Mozilla documentation, there are some examples written with window.
in front of the timer functions and some without:
function delayedAlert() {
timeoutID = window.setTimeout(slowAlert, 2000);
}...
setTimeout(myArray.myMethod, 1000);...
window.setInterval = function (vCallback, nDelay...
I have been writing my code without window.
in front without any problem so far. I want to find out if there is any situation when it would be necessary.
If ..
x
orwindow
), and;with
binding that resolves the given name (x
orwindow
), and;x
) is a property in the global scope (window
).. then
window.x
andx
are equivalent.For standards-mandated global properties/functions (which must exist in the global scope of a sane web-browser environment), I do not include
window
. I also take care not to shadow such names.No you do not have to add it, the 'window' part is implicit as the root object is
window
. However, people continue to add it as it denotes a built-in, rather than a user defined function.