Javascript examples for Function:Function Async
make a function wait for one seconds
<html> <head> <meta name="viewport" content="width=device-width, initial-scale=1"> <script type="text/javascript"> window.onload=function(){/*www . ja va2 s. co m*/ function sleep (duration) { var end = new Date().getTime() + duration; while(new Date().getTime() < end) { console.log('sleeping'); } } console.log('start: ' + (new Date().toString())); sleep(1000); console.log('end: ' + (new Date().toString())); } </script> </head> <body> </body> </html>