chodzi linią tego skryptu:Po co ustawiać konstruktor prototypu na jego funkcję konstruktora?
function Vehicle(hasEngine, hasWheels) {
this.hasEngine = hasEngine || false;
this.hasWheels = hasWheels || false;
}
function Car (make, model, hp) {
this.hp = hp;
this.make = make;
this.model = model;
}
Car.prototype = new Vehicle(true, true);
Car.prototype.constructor = Car;
Car.prototype.displaySpecs = function() {
console.log(this.make + ", " + this.model + ", " + this.hp + ", " + this.hasEngine + ", " + this.hasWheels);
}
var myAudi = new Car ("Audi", "A4", 150);
myAudi.displaySpecs(); // logs: Audi, A4, 150, true, true
Moje pytanie brzmi: co ma
Car.prototype.constructor = Car;
zrobić? Co ważniejsze, jakie są konsekwencje tego, że tego nie robimy i w jakich okolicznościach jest to NAJBARDZIEJ pożyteczne?