Objects created using an object literal, or with new Object(), inherit from a prototype called Object.prototype.
Objects created with new Date() inherit the Date.prototype.
The Object.prototype is on the top of the prototype chain.
Creating a Prototype
The standard way to create an object prototype is to use an object constructor function:
With a constructor function, you can use the new keyword to create new objects from the same prototype:
The constructor function is the prototype for Person objects. It is considered good practice to name constructor function with an upper-case first letter.
Adding Properties and Methods to Objects
Sometimes you want to add new properties (or methods) to an existing object.
Sometimes you want to add new properties (or methods) to all existing objects of a given type.
Sometimes you want to add new properties (or methods) to an object prototype.
Adding a Property to an Object
Adding a new property to an existing object is easy:
The property will be added to myFather. Not to myMother. Not to any other person objects.
Adding a Method to an Object
Adding a new method to an existing object is also easy:
The method will be added to myFather. Not to myMother.
Adding Properties to a Prototype
You cannot add a new property to a prototype the same way as you add a new property to an existing object, because the prototype is not an existing object.
To add a new property to a constructor, you must add it to the constructor function:
Prototype properties can have prototype values (default values).
Adding Methods to a Prototype
Your constructor function can also define methods:
Using the prototype Property