Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

131
Visualizações
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
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda