Files
30-seconds-of-code/snippets/delay.md
30secondsofcode f70de3d88f Travis build: 1391
2018-01-24 12:34:41 +00:00

409 B

defer

Invokes the provided function after wait 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, wait, ...args) => setTimeout(fn, wait, ...args);
delay(
  function(text) {
    console.log(text);
  },
  1000,
  'later'
); // Logs 'later' after one second.