JavaScript doesn't actually have a sleep() function corresponding to what is available in other languages. We can easily implement one though. The following code uses afunc as an example function where we want to be able to have the code sleep for a number of milliseconds between sections of code. The allowSleep() method allows us to implement this simply by calling sleep() the same as in other languages provided that we do not try to sleep in the middle of a loop and provided there is no code after the end of the function - it rewrites our function for us to implement the sleep delays without having to manually rewrite the code and without locking up the browser (as setting up a loop or using Java, Flash, or a server side language called from JavaScript to do the sleep would require).
You can substitute any function for afunc() in this example and have the code work exactly as shown provided that the sleep() calls are not in a loop.