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

129
Visualizações
How can I call same-level method in base class?

This is the code I have

class Parent {
  async A(part, id) {
  }

  async B(part, id) {
    await this.A(part, id)
  }
}

class Child extends Parent {
  async A(id) {
  }

  async B(id) {
    await super.B("part1", id);
    // ...
  }
}

// let's assume I'm in async context
const child = new Child();
await child.B();

So what is happening here is the Child.B is calling Parent.B, and Parent.B is calling Child.A (which is expected).

I want to know if there is a way for me to call Parent.B > Parent.A.

I realize that perhaps I need to rename the methods, but I wanted to know if there is a way for this.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

If you want to call a method of a specific class instead of looking it up on the instance (on this) or your own prototype (trough super), reference that method directly and .call it on the instance:

class Parent {
  async A(part, id) {
  }

  async B(part, id) {
    await Parent.prototype.A.call(this, part, id)
  }
}
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