Files
30-seconds-of-code/snippets/delay.md
Isabelle Viktoria Maciohsek 5e8e6f51a3 Update snippet descriptions
2020-10-19 18:51:03 +03:00

446 B

title, tags
title tags
delay function,intermediate

Invokes the provided function after ms milliseconds.

  • Use setTimeout() to delay execution of fn.
  • Use the spread (...) operator to supply the function with an arbitrary number of arguments.
const delay = (fn, ms, ...args) => setTimeout(fn, ms, ...args);
delay(
  function(text) {
    console.log(text);
  },
  1000,
  'later'
); // Logs 'later' after one second.