Código:
El array televisores se rellena correctamente con todos los valores.function comenzar(){ var televisores = []; var mi_televisor_1 = new Televisor(20,"blanco","A",40,10,false); televisores.push(mi_televisor_1); var mi_televisor_2 = new Televisor(20,"azul","B",40,10,true); televisores.push(mi_televisor_2); var mi_televisor_3 = new Televisor(20,"blanco","C",40,10,false); televisores.push(mi_televisor_3); televisores.forEach(function(televisor, index){ televisor.calcularPrecioFinal(); console.log ('precioFinal: '+televisor.precioFinal); }); } //CLASE PRINCIPAL function Electrodomestico(precioBase, color, consumoEnergetico, peso ){ this.color=color || 'blanco'; this.consumoEnergetico=consumoEnergetico || "F"; this.precioBase=precioBase || 100; this.peso=peso || 5; this.precioFinal; this.calcularPrecioFinal = function() { //CALCULOS this.precioFinal = this.precioBase; } } //SUBCLASE function Televisor(precioBase, color, consumoEnergetico, peso, resolucion, sintonizador) { this.resolucion=resolucion || 20; this.sintonizador=sintonizador || false; this.base = Electrodomestico; this.base(precioBase, color, consumoEnergetico, peso); this.precioFinal = Electrodomestico.calcularPrecioFinal(); //ERROR isnot a function this.calcularPrecioFinal = function() { //CALCULOS this.precioFinal = this.precioFinal + 500; } } Televisor.prototype = new Electrodomestico ();
La pregunta es:
En la subclase Televisor, como capturo el valor de precioFinal "lo que está en negrita", que se calcula en la funcion calcularPrecioFinal de la clase principal???