D
Daz
Hi everyone.
I have a relatively simple question which is hindered only by my lack
of understanding.
I am creating a clock (as if that's never been done before...), and I
was stuck as to whether I should use setTimeout() or setInterval().
One of the advantages I can see with using setInterval(), is that if
JavaScript is disabled, and then re-enabled, the setInterval() resumes
from where it left off. Can anyone confirm this for other browsers?
Anyhow... My main question, is that I don't know whether I can safely
use setTimeout() or setInterval(), at one second intervals safely, or
whether I am likely to lose any time over prolonged periods. For
example:
Would:
setInterval(function(){someFunctionThatGetsTheNumberOfSeconds();},
1000);
work the same as
setTimeout(function(){someFunctionThatGetsTheNumberOfSeconds();},
1000); ?
or would I be better of using something like:
setInterval(function(){someFunctionThatGetsTheNumberOfSeconds();},
200);
or
setTimeout(function(){someFunctionThatGetsTheNumberOfSeconds();},
200); ?
Obviously, the latter 2 are more CPU intensive, but is it overkill?
Could I run a reliable timer (in seconds), using 1 second intervals,
or should I check the seconds elapsed using the Date() object more
frequently?
I hope this make sense, as it's quite hard for me to word.
Many thanks in advance.
Daz.
I have a relatively simple question which is hindered only by my lack
of understanding.
I am creating a clock (as if that's never been done before...), and I
was stuck as to whether I should use setTimeout() or setInterval().
One of the advantages I can see with using setInterval(), is that if
JavaScript is disabled, and then re-enabled, the setInterval() resumes
from where it left off. Can anyone confirm this for other browsers?
Anyhow... My main question, is that I don't know whether I can safely
use setTimeout() or setInterval(), at one second intervals safely, or
whether I am likely to lose any time over prolonged periods. For
example:
Would:
setInterval(function(){someFunctionThatGetsTheNumberOfSeconds();},
1000);
work the same as
setTimeout(function(){someFunctionThatGetsTheNumberOfSeconds();},
1000); ?
or would I be better of using something like:
setInterval(function(){someFunctionThatGetsTheNumberOfSeconds();},
200);
or
setTimeout(function(){someFunctionThatGetsTheNumberOfSeconds();},
200); ?
Obviously, the latter 2 are more CPU intensive, but is it overkill?
Could I run a reliable timer (in seconds), using 1 second intervals,
or should I check the seconds elapsed using the Date() object more
frequently?
I hope this make sense, as it's quite hard for me to word.
Many thanks in advance.
Daz.