spacer
Yehuda Shiran October 27, 1999
Maximizing Object Model References
Tips: October 1999

Yehuda Shiran, Ph.D.
Doc JavaScript

Developer News
Microsoft Shows Off Silverlight 4, IE9 Plans
Metasploit Expands Vulnerability Test Framework
HyperCard Reborn?

The topmost object in JavaScript's object model is window. It encapsulates important objects, such as document, navigator, and location. When accessing a property (or method) of the window object, the object specification may be excluded. For example, the following statements both refer to the same JavaScript method:

window.open();
open();

When writing a script, you can use the notation of your choice. However, you should keep in mind that the first specification is much faster. Let's take a look at another object reference:

var url = location.href;

In order for the scripting engine to resolve this reference, it first attempts to find an object named location in the global look-up table. After looking through the entire table and not finding such a named item, the engine has to walk through the table again asking each of the global objects if it supports the location object. When it finally encounters the global window object, the object that exposes the location property, it can then retrieve the href property. A better way to handle this situation, especially on a page containing many globally named items, is to fully scope the reference as follows:

var url = window.location.href;

For more information on these issues, refer to Microsoft's documentation.


People who read this tip also read these tips:

Look for similar tips by subject:

internet.commediabistro.comJusttechjobs.comGraphics.com

Search:

WebMediaBrands Corporate Info

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | Shopping | E-mail Offers | Freelance Jobs

webref The latest from WebReference.com Browse >
Rolling Out Your Own HTML Application Version Control · HTML 5: Client-side Storage · Working with Ajax Server Extensions
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Wi-Fi Product Watch, November 2009 · Chip Market Recovering From '08 Collapse · Low-Cost Tools to Kickstart Your New Business