spacer
Yehuda Shiran October 7, 1999
Object Types
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

JavaScript supports two different types of objects. Built-in objects, such as Math, that you cannot modify. PI, for example, is a property of the Math object and obviously cannot be modified. User-defined objects are created by the author. The course object discussed on October 6, 1999, is a user-defined object.

An object can be a property of another object, thus creating an object hierarchy. Suppose an object a has two object properties, b and c. The object b has two properties, d and e, while the object c has four properties, f, g, h, and i. Let's assume that d is 16, e is 42, f is true, g is "king", h is 13, and i is 10. The following expressions are references to various properies in this object hierarchy:

alert(a.b.d) // prints 16
alert(a.b.e) // prints 42
alert(a.c.f) // prints true
alert(a.c.g) // prints king
alert(a.c.h) // prints 13
alert(a.c.i) // prints 10

A property belongs to an object, and only to one object. A variable may be named exactly like a property of an object. The following statement is valid:

d = a.b.d;

However, a variable cannot have the same name as an object at the same level (scope). The following statement is not valid:

a = a.b.d;

It's good practice to avoid repeating names.


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