| Q1: | Many objects in JavaScript, such as DOM objects, include 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 assign a new object to each array element (for example, cardarray[1] = new Card();). You can use a loop, described in the next hour, to assign objects to an entire array at once. |
| Q3: | Can I modify all properties of objects? |
|
A3:
| With custom objects, yesbut this varies with built-in objects and DOM objects. For example, you can use the length property to find the length of a string, but it is a read-only property and cannot be modified. |