spacer
Yehuda Shiran October 7, 1999
Object Types
Tips: October 1999

Yehuda Shiran, Ph.D.
Doc JavaScript

Developer News
News Flash: Adobe Has iPhone Workaround
Adobe's Flash 10.1 Goes Mobile (Minus iPhone)
A Salute to Visionary CEOs

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, Reprints, Permissions, Privacy Policy.
Advertise | Newsletters | Shopping | E-mail Offers | Freelance Jobs

webref The latest from WebReference.com Browse >
Building a Banking Application Home Page with OOP · Mixing Scripting Languages · Review: phpFox, a Social Networking CMS with all the Bells and Whistles
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Enterprise 2.0: Social Networking in the Cloud · BroadSoft Marketplace Hastens Pace of Telephony Innovation · Review: HTC Hero for Sprint