Files
30-seconds-of-code/snippets/delay.md
2018-01-25 18:53:03 -06:00

21 lines
409 B
Markdown

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