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

204
Visualizações
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 Respostas
Responde à pergunta

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