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

122
Visualizações
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 Respostas
Responde à pergunta

0

You can do that with this.constructor:

findRecipe(){
    doStuffWith(this.constructor.recipeType);
}
about 4 years ago · Juan Pablo Isaza Relatório
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