JavaScript custom wait for wait function instance analysis
- 2020-05-17 04:49:29
- OfStack
This article demonstrates the use of the JavaScript custom wait wait function as an example. Share with you for your reference. The specific analysis is as follows:
Here is a custom js wait function that suspends the execution of the program
function sleep(delay)
{
var start = new Date().getTime();
while (new Date().getTime() < start + delay);
}
//usage
//wait for 3 seconds
sleep(3000);
I hope this article has been helpful to your javascript programming.