Is Using SetTimeout(fn, 0) To Defer Code Execution Until After The Current Call Stack Reliable?
I've got a function that is called an unknown number of times. I need to know how many times the function was run so I'm doing: (function () { var i = 0, increment
Solution 1:
setTimeout() places a function on the queue, which is executed when all the other functions have been run.
If you call setTimeout() a few times before calling increment(), you will probably notice the i variable reaching a value greater than 1.
Solution 2:
Yes this code snippet seems to be reliable across all browsers even in the lowest version of IE. I tried this in IE8 I works good.
Post a Comment for "Is Using SetTimeout(fn, 0) To Defer Code Execution Until After The Current Call Stack Reliable?"