En cuanto a una línea de este guión:¿Por qué configurar el constructor del prototipo a su función de constructor?
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
Mi pregunta es: ¿qué
Car.prototype.constructor = Car;
hacer? Más importante aún, ¿cuáles son las consecuencias de no hacer esto y en qué circunstancias es más útil?