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

187
Vistas
if/else for specified function names that were called?

Is it possible to create an if else statement that depends on whether a certain function was called or not? If so, how do I define that in the if/else statement?

for example:

    function getUseLocators(){
    if (a function named 'function01' or 'function02' was called) {
        return true;
    } else {
        return w.checkUseLocators.value;
    }
}
about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

There is no such thing as "function was called" in native JavaScript, you could do it with a higher order function like this:

function function01() {
  console.log('function01');
}

function function02() {
  console.log('function02');
}

const [makeObservableFunction, wasCalled] = (function() {
  
  const called = [];

  function make(func, name) {
    return function(...args) {
      called.push(name);
      func(...args);
    }
  };
  
  function wasCalled(name) {
    return called.includes(name);
  };
  
  return [make, wasCalled];
})();

const observableFunction01 = makeObservableFunction(function01, 'function01');
const observableFunction02 = makeObservableFunction(function02, 'function02');

function getUseLocators() {
    console.log(wasCalled('function01') || wasCalled('function02'));
}

getUseLocators();

observableFunction01();

getUseLocators();

about 4 years ago · Juan Pablo Isaza Denunciar

0

You will need to store state to figure out if it was called.

let wasCalled = false;
function one(){
   wasCalled = true;
}

function two(){
  if (wasCalled) {
     console.log('One was called');
  } else {
     console.log('One was not called');  
  }
}


two();
one();
two();

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