On Jan 14, 11:06 am, SARFRAZ AHMED <[email protected]> wrote:
> You might have heard that setInterval is bad. The reason is that
> setInterval keeps on calling itself irrespective of whether or not the
> callback function completed.
>
> Well, one can mimic the setInterval using setTimeout in combination
> with self-invoking functions.
>
> Here is an example:http://jsbin.com/usali4
>
> Code Used:
>
> (function foo(){
> alert('I will get called on page load and after 10 seconds again and
> again without setInterval :)');
>
> setTimeout(foo, 10000);
>
> })()
To really mimic setInterval you've got to put the setTimeout at the
very beginning of foo, before the alert.
(function foo(){
setTimeout(foo, 10000);
alert('I will get called on page load and after 10 seconds again and
again without setInterval :)');
})()
--
Jorge.
--
To view archived discussions from the original JSMentors Mailman list:
http://www.mail-archive.com/[email protected]/
To search via a non-Google archive, visit here:
http://www.mail-archive.com/[email protected]/
To unsubscribe from this group, send email to
[email protected]