HTML and CSS Reference
Figure 8.18 Testing objects.
In the previous examples, we used the prototype object to extend properties and methods
for a given class. In the next chapter you will see how to use prototyping to customize
Now, to demonstrate how inheritance works, we will define a base class called Pet,
which will have its own properties and methods and can create instances via the “new”
operator . Then we will use this base class to create two additional subclasses called Cat
and Dog. Each of these subclasses (derived classes) will use the prototype property to
inherit the properties and methods of the Pet class (see Figure 8.19). Both the Cat and
the Dog class will be customized to have their own speak() method. Even though the
speak() method for the object to which it belongs; that is, when the speak() method is
called for a Cat object, it will return “Meow”, and when called for a Dog object, it will
say “Woof”. See Example 8.15 for the program code.
Figure 8.19 A hierarchical tree-like structure used to describe base class and