Many workarounds are there to try to implement such functions. setInterval ( function, milliseconds) Same as setTimeout (), but repeats the execution of the function continuously. I understand that using setTimeout() involves more thought than a desirable sleep() function, but unfortunately the later doesn't exist. The two key methods to use with JavaScript are: setTimeout ( function, milliseconds) Executes a function, after waiting a specified number of milliseconds. Var y = null // To keep under proper scope You use setTimeout() to rewrite it this way: var x = 1 Place mysterious code that blocks the thread for 100 ms. It's not that hard to use actually, instead of writing this: var x = 1 Unfortunately, setTimeout() is the only reliable way (not the only way, but the only reliable way) to pause the execution of the script without blocking the UI.
0 Comments
Leave a Reply. |