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

195
Views
cache existing function and add to it and run additions when another function called

I have the following existing function that I'm unable to access and change. So I've had to cache it and add other functions to it.

The function loads periodically and sometimes load on page load and sometimes doesn't. The additional functions I've added to it , I don't ever want loading on page load however.

I have tried the following with no luck. I can not prevent update_scores from loading on page load , so the if(onSwitch) is true , then and only then I want to add something else to the existing function. Once onSwith is true , then I need all additional functions to always execute when update_scores runs, but initially only after another function click() is called.

function click() {
    update_scores(true);
}

update_scores = (function(onSwitch) {
    var cached_function = update_scores;
    return function() {
        let update_scores=true; // always do something below when update_scores after function click ran once
        cached_function.apply(this, arguments);
            if(onSwitch) {                    
               //Do something only when function click is ran or until onSwith is defined as true
            }
    };
}());
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

ok , i was able to achieve by setting a global variable , then changing it when i ran another function

var onSwitch = false;

function click() {
    update_scores(true);
    onSwitch = true;
}

update_scores = (function(onSwitch) {
    var cached_function = update_scores;
    return function() {
        cached_function.apply(this, arguments);
            if(onSwitch) {                    
               //Do something only when function click is ran or until onSwith is defined as true
            }
    };
}());
about 4 years ago · Juan Pablo Isaza Report
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!