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.
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 objects using a function as a constructor (with
new), the objects will have a secret link pointing to their prototype, and can access the prototype's properties as their own.
Own properties take precedence over prototype's properties with the same name.
hasOwnProperty()method to differentiate between own properties and prototype properties.
There is a prototype chain: if your object
foodoesn't have a property
bar, when you do
barproperty of the prototype. If none is found, it will keep searching in the prototype's prototype, then the prototype of the prototype's prototype and keep going all the way up to the highest-level parent