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

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:

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