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

282
Vistas
TypeError [ERR_INVALID_CALLBACK]

I want to Implement a function which can run a given function after a delay.

Arguments:

  • callback: the function to execute after the delay
  • delay: number of milliseconds to wait
  • data: the one (and only) argument to pass to the callback

And this was my code

let cb = function(x) {
  console.log(x);
};

const doShortly = function(callback, delay, data) {
  let result = setTimeout(callback(data), delay);
  return result;
};

console.log(doShortly(cb, 500, 'hi'));

I get TypeError [ERR_INVALID_CALLBACK] when I run the code. May I know how to fix this. TIA.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You can use setTimeout or setInterval for that directly. All the params after the delay param, will be passed to the callback function in the same order :)

let cb = function(x) {
  console.log(x);
};

const doShortly = function(callback, delay, data) {
  let result = setTimeout(callback, delay, data);
  return result;
};

console.log(doShortly(cb, 500, 'hi')); // or: setTimeout(cb, 500, 'hi')

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