Rename js snippets
This commit is contained in:
27
snippets/js/s/delay-function.md
Normal file
27
snippets/js/s/delay-function.md
Normal file
@ -0,0 +1,27 @@
|
||||
---
|
||||
title: Delay function execution
|
||||
type: snippet
|
||||
language: javascript
|
||||
tags: [function]
|
||||
cover: interior-13
|
||||
dateModified: 2020-10-19T18:51:03+03:00
|
||||
---
|
||||
|
||||
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.
|
||||
|
||||
```js
|
||||
const delay = (fn, ms, ...args) => setTimeout(fn, ms, ...args);
|
||||
```
|
||||
|
||||
```js
|
||||
delay(
|
||||
function(text) {
|
||||
console.log(text);
|
||||
},
|
||||
1000,
|
||||
'later'
|
||||
); // Logs 'later' after one second.
|
||||
```
|
||||
Reference in New Issue
Block a user