All JavaScript objects inherit properties and methods from a prototype.
Date objects inherit from Date.prototypeArray objects inherit from Array.prototypePerson objects inherit from Person.prototypeThe Object.prototype is on the top of the prototype inheritance chain:
Date objects, Array objects, and Person objects inherit from Object.prototype
function Person(first, last, age, eyecolor) {
this.firstName = first;
this.lastName = last;
this.age = age;
this.eyeColor = eyecolor;
}
Person.prototype.nationality = "English";
Person.prototype.name = function() {
return this.firstName + " " + this.lastName;
};
var myFather = new Person("John", "Doe", 50, "blue");
var myMother = new Person("Sally", "Rally", 48, "green");
❗Please do not add a new property to an existing object constructor as below. That is a wrong way.
Person.nationality = "English";