I created a simple constructor like:
function Car() {
this.noTires = 5;
}
Car.__proto__
prints out Empty() {}
What does this mean?
I created a simple constructor like:
function Car() {
this.noTires = 5;
}
Car.__proto__
prints out Empty() {}
What does this mean?
protoype is a property of every constructor It is an object which is a prototype of a new instance. you can define it something like this.
Car.prototype.name="Audi";
Car.prototype.model="A4";
making a constructor does not mean making a prototype. Prototypes are used when we want to make instances pointeng to the same block eg.
function Person(){
}
Person.prototype.name = "detailer";
Person.prototype.age = 17;
Person.prototype.job ="Developer"
Person.prototype.sayName = function(){
alert(this.name);
};
var person1 = new Person();
var person2 = new Person();
person1.name = "lakshay";
alert(person1.name); //lakshay - from instance
alert(person2.name); //detailer - from prototype