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

132
Vistas
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 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