Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

221
Vistas
Javascript (howler js) How to pass child property to parent?

Good day everyone, I'm fairly new to Javascript so please forgive me if this is a stupid question. I've been trying to google this, some say to use super() but I'm getting an error of undefined.

I'm using howlerJS. My goal is not to rewrite the same 'onend' listener/function whenever I instantiate a new Howl.

class ChildHowl extends Howl{
    ...how can i insert 'onend' prop here?...
}
var myHowl = new ChildHowl({
  src: ['audio.wav'],
  // how to move this onend to ChildHowl as a default
  onend: function() {
        console.log('audio ended');
        .... some stuff ....
      }
});

Thank you everyone in advance. You're understanding and consideration is highly appreciated.

Update: Fixed thank you Fabien Auréjac for the help!

class ChildHowl extends Howl{ 
  constructor(obj) { 
    let onend=function() { 
      console.log('audio ended'); 
    }; 
    super({ src:obj.src, onend:onend }); 
  } 
}

var myHowl = new ChildHowl({
  src: ['audio.wav']
});
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Welcome, you can pass the argument via super(); in order to get the constructor of your parent class to receive it.

class Howl {
    constructor(obj) {
        console.log(obj);
        this.src = obj.src;
        this.onend = obj.onend;
    }
}
class ChildHowl extends Howl{
    constructor(obj) {
        super(obj);
        this.onend();
    }
}
var myHowl = new ChildHowl({
    src: ['audio.wav'],
    onend: function() {
        console.log('audio ended');
    }
});
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda