¿Por qué establecer el constructor del prototipo en su función de constructor? [duplicar
Esta pregunta ya tiene una respuesta aquí:
¿Por qué es necesario configurar el constructor prototipo? 13 respuestasEn cuanto a una línea de este script:
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é hace
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?