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

196
Vistas
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 Respuestas
Responde la pregunta

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