HTML and CSS Reference
EXAMPLE 8.12 ( CONTINUED )
document.write(book1.title + " is published by "+
book1.publisher + "<br />");
document.write(book2.title + " is published by " +
The constructor function called Book will define the properties and methods for
a Book class. The function takes two parameters.
Two new Book objects are created, book1 and book2 .
The Book class has a prototype object. It is assigned a property called publisher .
Now the publisher property and its value are available to all Book objects.
In the last example only book1 got the new property. Now both book1 and book2
have inherited the publisher property found in the Book's prototype (see Figure
8.14). If you don't want all topics to be published by “Penguin Books” you could
set the value of the publisher to “Unknown” as a default and change it later; for
example, book2.publisher=“Viking Press” and the book2 object would get the value
Figure 8.14 Using the prototype for inheritance.
property was defined directly for that object; for example, does the Book object have a
go up to the parent object. This process of going up the hierarchy, called the prototype