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

220
Views
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 answers
Answer question

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 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!