Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.

  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

8. Function Prototype Property > Creating Inheritance Chains (the Original Inte...

Creating Inheritance Chains (the Original Intention)

Prototypal inheritance was conceived to allow inheritance chains that mimic the inheritance patterns found in traditional object-oriented programming languages. Inheritance is simply one object being given access to another object’s properties. This is done by instantiating an instance of the object you want to inherit from as the value for the prototype property of the function that creates the object that is doing the inheriting. When this is done, there is a link (a.k.a. __proto__) between the objects that extends the available properties to an object upon property lookup.

In the code below, Chef objects (i.e., cody) inherit from Person().This means that if a property is not found in a Chef object, it will next be looked for on the prototype of the function that created Person() objects. To wire up the inheritance, all you have to do is instantiate an instance of Person() as the value for Chef.prototype (i.e., Chef.prototype = new Person(); ).


  

You are currently reading a PREVIEW of this book.

                                                                                                                    

Get instant access to over $1 million worth of books and videos.

  

Start a Free Trial


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint