I have a function startTime()
that handles a clock showed on the page, and the last line of this function is var t = setTimeout(function(){ startTime() }, 1000);
.
Being a recursive function with a timeout, what are the implications in performance? Does it consumes more and more memory as time passes by? I mean, if I leave this page opened during one day, and compare it to being open for a week, what are the difference? If this approach is not so good, is there a better one to this? Also, feel free to give some tips to my code (standards and better typing).
Thanks!
Complete code:
function startTime() {
var today = new Date();
var h = today.getHours();
var m = today.getMinutes();
var s = today.getSeconds();
// function checkTime(): add a zero in front of numbers<10
h = checkTime(h);
m = checkTime(m);
s = checkTime(s);
var t_hora = h + ":" + m;
document.getElementById("clock").innerHTML = t_hour + ":" + s;
if (s%20 <= 10) {
document.title = t_hour;
} else {
document.title = "My customized title";
}
var t = setTimeout(function(){ startTime() }, 1000);
}
function checkTime(i) {
if (i < 10) {
i = "0" + i;
}
return i;
}