Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

177
Views
¿Cómo puedo saber si una función ha sido llamada o no?

Estoy haciendo un pequeño módulo reutilizable para mi uso. y me detuve en un punto de mi código que es, ¿cómo puedo asegurarme de que el consumidor de mi módulo haya llamado a una función que le proporcioné o no en uno de los métodos de mi módulo?

Básicamente, la API del módulo se parece al método forEach, donde mi módulo pasa argumentos internos tal como funciona forEach

 myModule.myMethod(callbackFunc, z)

myModule llama internamente a su callbackFunc con los siguientes argumentos: anotherFunc , x , y

Ejemplo de uso:

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

¿Cómo puedo saber si el consumidor de myMethod ha llamado passed_function o no?

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Suponiendo que anotherFunc es algo que crea internamente, puede escribirlo para que actualice un booleano, y luego puede verificar ese booleano. Por ejemplo:

 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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!