javascript prototype explained

JavaScript
function Person(name) {
  this.name = name;
}
Person.prototype.getName = function() {
  return this.name;
}

var person = new Person("John Doe");
person.getName() //"John Doe"/* Answer to: "javascript prototype explained" */

/*
  The prototype object is special type of enumerable object to
  which additional properties can be attached to it which will be
  shared across all the instances of it's constructor function.

  So, use prototype property of a function in the above example
  in order to have age properties across all the objects as
  shown below:
*/

function Student() {
    this.name = 'John';
    this.gender = 'M';
}

Student.prototype.age = 15;

var studObj1 = new Student();
alert(studObj1.age); // 15

var studObj2 = new Student();
alert(studObj2.age); // 15function Person(first, last, age, eye) {
this.firstName = first;
this.lastName = last;
this.age = age;
this.eyeColor = eye;
}

Person.prototype.nationality = "English";

var myFather = new Person("John", "Doe", 50, "blue");
console.log("The nationality of my father is " + myFather.nationality)
Source

Also in JavaScript: