This figure again shows that every object has a prototype. Constructor function Foo also has its own
__proto__
which is Function.prototype, a
(number inside the parenthesis () is a 'link' to the code that is written below)
prototype
- an object that consists of:
=> functions (3) of this
particular ConstructorFunction.prototype
(5) that are accessible by each
object (4) created or to-be-created through this constructor function (1)
=> the constructor function itself (1)
=> __proto__
of this particular object (prototype object)
__proto__
(dandor proto?) - a link BETWEEN any object (2) created through a particular constructor function (1), AND the prototype object's properties (5) of that constructor THAT allows each created object (2) to have access to the prototype's functions and methods (4) (__proto__
is by default included in every single object in JS)
1.
function Person (name, age) {
this.name = name;
this.age = age;
}
2.
var John = new Person(‘John’, 37);
// John is an object
3.
Person.prototype.getOlder = function() {
this.age++;
}
// getOlder is a key that has a value of the function
4.
John.getOlder();
5.
Person.prototype;