I have two constructor functions here: Car and Van
var Car = function (location) {
this.loc = location
};
Car.prototype.move = function () {
this.loc++
}
var Van = function (location) {
Car.call(this, location)
}
Could you tell me what this line Car.call(this, location) is doing? My assumption is that we want to inherit the loc property from the Car class to the Van class.
My confusion is on what now this inside
Car.call(this, location)
is referring to? and also what this inside Car
var Car = function (location) {
this.loc = location
};
is referring to? Can someone provide any insight?
Car.call(this, location)
this will associate the .loc property to the Van object. this here refers to the Van.
If you instantiate Van, it will associate the same
var v = new Van(1); // v.loc=1