Every function you create has a property called prototype
, and it starts off its life as an empty object. This property is of no use until you use this function as constructor function i.e. with the 'new' keyword.
This is often confused with the __proto__
property of an object. Some might get confused and except that the prototype
property of an object might get them the proto of an object. But this is not case. prototype
is used to get the __proto__
of an object created from a function constructor.
In the above example:
function Person(name){_x000D_
this.name = name_x000D_
}; _x000D_
_x000D_
var eve = new Person("Eve");_x000D_
_x000D_
console.log(eve.__proto__ == Person.prototype) // true_x000D_
// this is exactly what prototype does, made Person.prototype equal to eve.__proto__
_x000D_
I hope it makes sense.