HTML and CSS Reference
In-Depth Information
lookup chain, can continue until JavaScript reaches the top of the chain. You might
recall that the top object is called the Object object and it too has a prototype .
Example 8.13 uses the prototype for the Object object and the prototype for the Book
object to create new properties. To retrieve a property for a Book object, JavaScript
would look up the property in the following order:
1. The object itself
2. The Book.prototype
3. The Object.prototype
First JavaScript starts with a Book object. If looking for the Book's title and author ,
then there is no need to look further; if, on the other hand, we want to get the publisher
or category , then JavaScript will go up the chain and look at the Book's prototype, and
finally, if not there, go to the top Object object and look there (see Figure 8.15). If the
Object object has not defined the property, it is undefined . (Much of the information in
this paragraph should be credited to a paper on objects written by Mike Koss at
http://mckoss.com/jscript/object.htm. )
Constructors
Prototype Chain
Object
Object.prototype.category
function
Book()
Book.prototype.publisher
book1
book2
book1.author
book2.author
book1.title
book2.title
Figure 8.15 JavaScript looks for the property with Example 8.13.
 
Search WWH ::




Custom Search