This is another name for the window.self property in this context. However, window is useful because you can remove the ambiguity associated with accessing global object properties and methods. Don't forget that this can also refer to a frame as well as a window since they are both represented by the window object.
If the script is running in the topmost window of a frame-set or within a non-frame-set window, the top property will also be set to the same value.
This property is slightly odd, because the window object is also the global object for a web browser. The global object is always placed in the scope chain for a script's execution context. So, all properties that belong to the window are available without requiring the window object prefix.
So, these all refer to the same thing:
window
window.self
self
window.window
self.self
self.window.self
window.window.window.window.window.self.window
The main use of this property is to yield slightly better readability and clarity in the code you write. The same applies to the self property. It is better to explicitly call window.open() rather than just open(). Explicitly calling window.open() avoids an inadvertent call to document.open(). You might not be aware of an open() method belonging to another object that has been placed into the scope chain ahead of the window object.
Be careful if you are building recursive scripts to walk the window hierarchy, as you could find yourself in an endless loop simply walking via the window property of the top level window.
See also: | Frame object, Window object, Window.frame, Window.self, Window.top |
Prev | Home | Next |
Window.top | Up | Windows Script Host |
JavaScript Programmer's Reference, Cliff Wootton Wrox Press (www.wrox.com) Join the Wrox JavaScript forum at p2p.wrox.com Please report problems to support@wrox.com © 2001 Wrox Press. All Rights Reserved. Terms and conditions. |