Add delay

This commit is contained in:
Angelos Chalaris
2018-01-24 14:32:20 +02:00
parent fed4fc3238
commit 42cd69f391
2 changed files with 17 additions and 0 deletions

16
snippets/delay.md Normal file
View 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.
```

View File

@ -36,6 +36,7 @@ deepClone:object,recursion
deepFlatten:array,recursion deepFlatten:array,recursion
defaults:object defaults:object
defer:function defer:function
delay:function
detectDeviceType:browser detectDeviceType:browser
difference:array,math difference:array,math
differenceBy:array,function differenceBy:array,function