This figure again shows that every object has a prototype. Constructor function Foo also has its own
__proto__
which is Function.prototype, a
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){
this.name = name
};
var eve = new Person("Eve");
console.log(eve.__proto__ == Person.prototype) // true
// this is exactly what prototype does, made Person.prototype equal to eve.__proto__
I hope it makes sense.