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

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