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

120
Vistas
Can I refer to a static variable of a class without using its name? (for inheritance)

Let's say I have some code:

class BuildingWithRecipe {
    static recipeType = ""
    findRecipe(){
        doStuffWith([not this].recipeType);
    }
}

class Furnace extends BuildingWithRecipe {
    static recipeType = "smelting"
}

I want to be able to access a static method of a class with a keyword inside of an instance method of that class, so when I extend BuildingWithRecipe(lets say with Furnace) I can simply set the static recipeType property and the findRecipe method will access Furnace.recipeType instead of BuildingWithRecipe.recipeType when called on an instance of Furnace.

Is this possible?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You can do that with this.constructor:

findRecipe(){
    doStuffWith(this.constructor.recipeType);
}
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