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 > Instances Created From a Constructor Function ...

Instances Created From a Constructor Function are Linked to the Constructor’s prototype Property

While it’s only an object, prototype is special because the prototype chain links every instance to its constructor function’s prototype property. This means that any time an object is created from a constructor function using the new keyword (or when an object wrapper is created for a primitive value), it adds a hidden link between the object instance created and the prototype property of the constructor function used to create it. This link is known inside the instance as __proto__ [though it is only exposed/supported via code in Firefox 2+, Safari, Chrome, and Android]. JavaScript wires this together in the background when a constructor function is invoked and it’s this link that allows the prototype chain to be, well, a chain. Below, we add a property to the native Array() constructor’s prototype, which we can then access from an Array() instance using the __proto__ property set on that instance.


  

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