0

Any time I have included an alert in a Javascript program, I have simply called it as "alert", for example,

alert("The value of the variable is presently " + varValue + ".");

However, I also see code that calls it as window.alert. For example,

window.alert("The value of the variable is presently " + varValue + ".");

Is there any difference between calling it one way or the other?
Is one considered better style than the other?

Does calling it by window.alert avoid some overhead (i.e. - save the program the problem of resolving where the alert comes from), thereby making the program execute more quickly?

Votes + Comments
a correct answer has been given to you - you need to say THANK YOU and mark your thread as "Solved"
3
Contributors
2
Replies
21
Views
4 Years
Discussion Span
Last Post by Troy III
0

alert is an object, which happens to be of type function, of the window. Anything in the window can be called directly, and in a "global" scope.

window.alert and alert are essentially the same thing.

1

the difference between alert("string") and window.alert("string") is:
an { implicit call to alert function } vs { explicit call to the same }.

You can also call self.alert("string"); top.alert("string"); this.alert("string"); ...but!
They are all the same.

The "alert" function of any window, is inherited through its prototype. Which means that this frame alert is not the same as that frame alert.
That would be the main and deliberate difference.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.