In Javascript, like setInterval(draw,20) you don’t include anything like in C#. You can just use the function. The function is on the Windows object of the browser.
-
Can the following objects and its functions be called without any pre-definitions?
Window Navigator Screen History Location -
Does JavaScript has any built-in functions?
In Javscript, there are certain things which are part of the language and will also be there. Native objects, like
Array(),String()andNumber(). (Not a complete list). These need no prefix in front of them, because there are none.In addition, when running on the browser the host environment provides a global variable called
windowthat is the same as the anonymous Javascriptglobalthat everything runs in. Methods of thewindowobject include things likealert()andsetTimeout()Alert can be called with
window.alert()or more often by justalert()itself. (Some people consider callingwindow.alert()best practice to a) show you are calling the global function and b) protect you from any local variables namedalert.)Clarification:
The Javascript engine keeps a global variable with no name and not normally accessible. When not running in struct mode, undeclared variables are created as properties in this global object, all global functions are put in the global object and
thisnormally called functions points to the global object.When running in the browser,
windowis the global object.