Sams Teach Yourself JavaScript in 24 Hours

Sams Teach Yourself JavaScript in 24 Hours

By Michael Moncur

Q&A

Q1:

The objects described in Hour 9 included parent and child objects. Can I include child objects in my custom object definitions?

A1:

Yes. Just create a constructor function for the child object, and then add a property to the parent object that corresponds to it. For example, if you created a Nicknames object to store several nicknames for a person in the card file example, you could add it as a child object in the Card object's constructor: this.nick = new Nicknames();

Q2:

Can I create an array of custom objects?

A2:

Yes. First, create the object definition as usual and define an array with the required number of elements. Then use a loop to assign a new object to each array element (for example, cardarray[1] = new Card();).

Q3:

Which browsers support custom objects?

A3:

The features described in this hour are included in JavaScript 1.1 and later, and should be supported by Netscape 3.0 or later and Internet Explorer 4.0 and later.

Share ThisShare This

Informit Network