Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

160
Views
javascript super, propiedades adicionales que devuelven indefinidas

estaba aprendiendo sobre la herencia en un curso, sin embargo, encontré la palabra clave super en MDN, comencé a implementarla y funciona, devolverá las dos propiedades que también están en la clase principal, pero la propiedad adicional que trato de implementar en la clase secundaria siempre devuelve indefinido, ¿cómo puedo implementar esto para agregar propiedades de la manera correcta? Como llegué a entender, podría estar equivocado, es súper aplica la palabra clave this a la clase principal. aqui esta mi codigo...

 class Car { constructor(speed, make){ this.speed = speed, this.make = make } get speed() { return this._speed / 1.6; } set speed(mov){ this._speed = mov * 1.6 } accel(){ console.log(this.speed += 5); } } const chevy = new Car(120, 'chevy'); //challenge 3 class Ev extends Car{ constructor(speed,make,bat){ super(speed,make) this.bat } billy(){ console.log('hi'); } chargeBat(charge){ this.bat = charge; return `ur battery is charging to ${charge}`; } cel(){ this.speed += 20; this.bat - 1; return `your car is going ${this.speed} and battery is ${this.bat}` } } // Ev.protype = Object.create(Car.prototype); const prius = new Ev(35,'prius',99); // console.log(prius.chargeBat()); // console.log(prius.cel()) console.log(prius.bat); console.log(prius.speed)
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Tiras el valor del bat en el constructor Ev. Guárdelo en this.bat para corregir eso. Vea el código a continuación.

 class Car { constructor(speed, make){ this.speed = speed, this.make = make } get speed() { return this._speed / 1.6; } set speed(mov){ this._speed = mov * 1.6 } accel(){ console.log(this.speed += 5); } } const chevy = new Car(120, 'chevy'); //challenge 3 class Ev extends Car{ constructor(speed,make,bat){ super(speed,make) this.bat = bat; // <------------- HERE } billy(){ console.log('hi'); } chargeBat(charge){ this.bat = charge; return `ur battery is charging to ${charge}`; } cel(){ this.speed += 20; this.bat - 1; return `your car is going ${this.speed} and battery is ${this.bat}` } } // Ev.protype = Object.create(Car.prototype); const prius = new Ev(35,'prius',99); // console.log(prius.chargeBat()); // console.log(prius.cel()) console.log(prius.bat); console.log(prius.speed)

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!