Add delay
This commit is contained in:
16
snippets/delay.md
Normal file
16
snippets/delay.md
Normal file
@ -0,0 +1,16 @@
|
||||
### 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.
|
||||
|
||||
```js
|
||||
const delay = (fn, wait, ...args) => setTimeout(fn, wait, ...args);
|
||||
```
|
||||
|
||||
```js
|
||||
delay(function(text) {
|
||||
console.log(text);
|
||||
}, 1000, 'later'); // Logs 'later' after one second.
|
||||
```
|
||||
@ -36,6 +36,7 @@ deepClone:object,recursion
|
||||
deepFlatten:array,recursion
|
||||
defaults:object
|
||||
defer:function
|
||||
delay:function
|
||||
detectDeviceType:browser
|
||||
difference:array,math
|
||||
differenceBy:array,function
|
||||
|
||||
Reference in New Issue
Block a user