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

108
Visualizações
Is that correct way to use .bind function in this situation?

I would like to know your opinion which is the best way to do that:

I have two classes:

class Application {
    ...
    pause() {}
    resume() {}
    ...
}

(Just image that the Application class is a big one. Which has a lot of methods and properties.)

class System {
    constructor(app: Application) {
        this.pauseCallback = app.pause.bind(app)
        this.resumeCallback = app.resume.bind(app)
    }
    
    onWindowInactive() {
        this.pauseCallback()
    }

    onWindowActive() {
        this.resumeCallback()
    }
}

The reason why I'm using .bind function on these methods is because I don't want to assign a reference to Application class in System class. So, I can do like this.app.pause() but I don't want to do that.

Instead of this I'm creating new functions using .bind and assigning them to System class properties. Then I can use pause and resume methods of Application

Is that the correct way to do that and what about performance and memory allocation?

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