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

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

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