Created
February 28, 2019 16:23
-
-
Save leolanese/b531169c374ab61cc9c5ed9dcff6e5b0 to your computer and use it in GitHub Desktop.
The function creates a new function that adds a delay in milliseconds to the execution of another function that is passed as an argument.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function addDelay(func: () => void, ms: number) { | |
return () => { | |
setTimeout(() => { | |
func(); | |
}, ms); | |
}; | |
} | |
function sayHello() { | |
console.log('Hello world!'); | |
} | |
const delayedSayHello = addDelay(sayHello, 600); | |
delayedSayHello(); // Prints "Hello world!" (after 600 ms) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment