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

Yehuda Shiran, Ph.D.
Doc JavaScript

Developer News
OpenOffice 3.2 Lands Amid Critical Changes
Red Hat, IBM Firmly in KVM Virtualization Camp
Red Hat Talks Up Open Source Cloud Plans

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:


The Network for Technology Professionals

Search:

About Internet.com

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

webref The latest from WebReference.com Browse >
Search Engine Optimization: Selecting and Embedding Keywords · Are Google's Language Translation Web Services Ready for Prime Time? · Installing and Using Meeplace, the Business Review CMS
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
IBM DB2 10 for z/OS: Justifying the Upgrade · Living La Vida Colo: Choosing the Right Colocation Facility · FTC Concerns over Social Media Privacy Linger