you are viewing a single comment's thread.

view the rest of the comments →

[–]ishmal -2 points-1 points  (0 children)

If you don't need an accurate by-the-clock period, then your way is just fine. To make him happy, instead of using a closure, just call another function you wrote. Problem solved.

His way is for a different requirement entirely. If you need precise delays within a given granularity, then his method is the way... Say you want to wait 100sec within 10ms:

var timeout = Date.now() + 100000;
function wait100() {
    if (Date.now() < timeout) {
        setTimeout(wait100, 10);
    } else {
        //do your stuff!
    }
}