"too much recusion" avec setTimeOut()
Bonsoir,
J'ai un petit souci (qui dure ça fait 3h xD) avec le fonction setTimeOut.
Il s'agit d'un chrono que j'appelle toutes les millisecondes.
La console m'affiche "too much recursion".
Voici le code :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
| this.chrono = function (chronoHTML){
this.end = new Date();
this.diff = this.end - this.start;
this.diff = new Date(this.diff);
var msec = this.diff.getMilliseconds();
var sec = this.diff.getSeconds();
var min = this.diff.getMinutes();
var hr = this.diff.getHours()-1;
if (min < 10){
min = "0" + min;
}
if (sec < 10){
sec = "0" + sec;
}
if(msec < 10){
msec = "00" +msec;
}else if(msec < 100){
msec = "0" +msec;
}
chronoHTML.innerHTML = hr + ":" + min + ":" + sec + ":" + msec;
this.timerID = setTimeout(this.chrono(chronoHTML), 10);
};
this.chronoGo = function(chronoHTML){
this.start = new Date();
this.chrono(chronoHTML);
}; |
Et l'appel :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
| "use strict";
(function(){
window.onload = function(){
//Unique Objet pour tout le jeu
var jeu = new HallOfFame.Game();
var j = new HallOfFame.Tools();
//Declarations elements DOM
var chrono = null;
//inits
chrono = document.getElementById("chronotime");
j.chronoGo(chrono);
};
})() |
Merci d'avance