Is there a need to add setTimeout and setInterval with the window?

The Mozilla documentation has some examples written using window. before timer functions, and some without:

 function delayedAlert() { timeoutID = window.setTimeout(slowAlert, 2000); }... setTimeout(myArray.myMethod, 1000);... window.setInterval = function (vCallback, nDelay... 

I am writing my code without window. front without any problems. I want to know if there is a situation when it will be necessary.

+2
javascript window settimeout setinterval
source share
2 answers

If a..

  • In the area with the given name, there is no other identifier ( x or window ) and;
  • There is no with binding that resolves the given name ( x or window ) and;
  • The given name ( x ) is a property in the global area ( window )

.. then window.x and x equivalent.

For standardized global properties / functions (which must exist in the global area of ​​a reasonable web browser environment) I do not enable window . I also try not to hide such names.

+2
source share

No, you do not need to add it, part of the "window" is implicit, since the root object is window . However, people continue to add it as it denotes a built-in function, not a user-defined one.

+1
source share

All Articles