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

Yehuda Shiran, Ph.D.
Doc JavaScript

Developer News
Mandrake Linux Founder Back, Virtually
Amazon: We're a Technology Company
Sun Expands MySQL With Closed Source
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.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

Jupitermedia Corporate Info

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

webref The latest from WebReference.com Browse >
Administering RBAC in PHP 5 CMS Framework · xref: Automatic Cross Referencing Script · Book Review: Content Rich
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
MS Access and MySQL · Cisco AutoQoS: VoIP QoS for Mere Mortals · While VoIP Adoption Explodes in Enterprise, Carrier Spending Lags