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

178
Visualizações
How can I know if a function has been called or not?

I'm making a small reusable module for my use. and stopped on a point in my code which is, how can I make sure that the consumer of my module has called a function I provided to him or not in one of the methods of my module?

Basically, the API of the module looks like the forEach method, where my module passes internally arguments just like how forEach works

myModule.myMethod(callbackFunc, z)

myModule internally calls your callbackFunc with the following arguments: anotherFunc, x, y

Example usage:

myModule.myMethod((anotherFunc, x, y) => {
    if (x == true) anotherFunc()
}, z)

How can I know that the consumer of the myMethod has called passed_function or not?

about 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

Assuming anotherFunc is something you create internally, you can write it so that it updates a boolean, and then later you can check that boolean. For example:

function myMethod(callback, z) {
  let hasBeenCalled = false;
  const anotherFunc = () => {
    hasBeenCalled = true;
    // ...
  }

  callback(anotherFunc, 'hello', 'world');

  if (hasBeenCalled) {
    console.log('they called it!');
  }
}
about 4 years ago · Santiago Trujillo 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