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

130
Views
It is possible to use a function of a child class in variable defined with parent class?

i am playing a bit with some code snippets and i am asking if its possible to use a function that was defined in a child class (with extends), to use in a variable that was created with the parent class?

Here is my code snippet:

class Workshop {
constructor(teacher) {
    this.teacher = teacher;
}
ask(question) {
    console.log(this.teacher, question);
}
}

class AnotherWorkshop extends Workshop {
    speakUp(msg) {
        console.log(msg);
    }
}

var shallowJS = new Workshop("Toby");

shallowJS.ask("you are there?");
shallowJS.speakUp("still there?");

Is there anyway, that i can access the function speakUp from the child class AnotherWorkshop with shallowJS.xxxx ? (and i dont mean the way to create a new variable of shallowJS)

Thanks a lot for help :)

about 4 years ago · Juan Pablo Isaza
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!