Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

107
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!