HTML and CSS Reference
In-Depth Information
The Object() constructor creates and returns a reference to a cat object.
The returned value from the Object() constructor is a reference to an object, as
shown in the Figure 8.2. [object Object] means that the cat is a descendant of the
Object object from which all objects are derived.
Figure 8.2 cat is an object.
8.1.3 Properties of the Object
Properties describe the object. The object name is followed by a dot and a property. The
properties are accessible only via their object. In Figure 8.3, the top object is the Object
object. If we create a new cat and a dog object, as shown in Example 8.2, they are descen-
dants of the Object object. Although the dog and the cat are objects in their own right,
they are considered properties of the Object object. In fact, any object subordinate to
another object is also a property of that object. The cat and the dog are descendants of
the Object object. They also have properties that describe them, such as name , color , size ,
and so forth. The Object object is not listed in the hierarchy when using the dot syntax.
To assign properties to the cat object, the syntax would be as follows: = "Sneaky";
In Example 8.2 a new object is created with the new keyword and the Object() construc-
tor. Properties are assigned to the object and their values retrieved.
<head><title>User-defined objects</title>
<script type = "text/javascript">
var toy = new Object(); // Create an instance of the object
3 = "Lego";
// Assign properties to the object
toy.color = "red";
toy.shape = "rectangle";
<body bgcolor="lightblue">
Search WWH ::

Custom Search