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

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

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 Relatório

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