Summary

Let's summarize the most important topics you have learned in this chapter:

  • All functions have a property called prototype. Initially it contains an "empty" object (an object without any own properties).
  • You can add properties and methods to the prototype object. You can even replace it completely with an object of your choice.
  • When you create an object using a function as a constructor (with new), the object gets a secret link pointing to the prototype of the constructor, and can access the prototype's properties.
  • An object's own properties take precedence over a prototype's properties with the same name.
  • Use the method hasOwnProperty() to differentiate between an object's own properties and prototype properties.
  • There is a prototype chain. ...

Get JavaScript : Object-Oriented Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.