setTimeout(): If not defined in EcmaScript spec, where can I learn how it works?

setTimeout and such aren’t in the ECMAScript specification because they’re not JavaScript features. They’re features of the browser environment’s window object. Other environments (Windows Scripting Host, NodeJS, etc.) won’t necessarily have those features. The W3C has been trying to standardize the window object and its various features (including setTimeout), the latest is in the timers … Read more

How to tell .hover() to wait?

This will make the second function wait 2 seconds (2000 milliseconds) before executing: $(‘.icon’).hover(function() { clearTimeout($(this).data(‘timeout’)); $(‘li.icon > ul’).slideDown(‘fast’); }, function() { var t = setTimeout(function() { $(‘li.icon > ul’).slideUp(‘fast’); }, 2000); $(this).data(‘timeout’, t); }); It also clears the timeout when the user hovers back in to avoid crazy behavior. This is not a very … Read more

What is the equivalent to a JavaScript setInterval/setTimeout in Android/Java?

As always with Android there’s lots of ways to do this, but assuming you simply want to run a piece of code a little bit later on the same thread, I use this: new android.os.Handler(Looper.getMainLooper()).postDelayed( new Runnable() { public void run() { Log.i(“tag”, “This’ll run 300 milliseconds later”); } }, 300); .. this is pretty … Read more

recursive function vs setInterval vs setTimeout javascript

Be carefull.. your first code would block JavaScript event loop. Basically in JS is something like list of functions which should be processed. When you call setTimeout, setInterval or process.nextTick you will add given function to this list and when the right times comes, it will be processed.. Your code in the first case would … Read more

What happens to setTimeout when the computer goes to sleep?

As far as I’ve tested, it just stops and resumes after the computer wakes up. When the computer awakes the setInterval/setTimeout is unaware that any time passed. I don’t think you should rely on the accuracy of setTimeout/Interval for time critical stuff. For google chrome I discovered recently that any timeout/interval (that is shorter than … Read more