Le délai d'attente était assez facile pour trouver une solution, mais l'intervalle était un peu plus délicat.
J'ai proposé les deux classes suivantes pour résoudre ces problèmes:
function PauseableTimeout(func, delay){
    this.func = func;
    var _now = new Date().getTime();
    this.triggerTime = _now + delay;
    this.t = window.setTimeout(this.func,delay);
    this.paused_timeLeft = 0;
    this.getTimeLeft = function(){
        var now = new Date();
        return this.triggerTime - now;
    }
    this.pause = function(){
        this.paused_timeLeft = this.getTimeLeft();
        window.clearTimeout(this.t);
        this.t = null;
    }
    this.resume = function(){
        if (this.t == null){
            this.t = window.setTimeout(this.func, this.paused_timeLeft);
        }
    }
    this.clearTimeout = function(){ window.clearTimeout(this.t);}
}
function PauseableInterval(func, delay){
    this.func = func;
    this.delay = delay;
    this.triggerSetAt = new Date().getTime();
    this.triggerTime = this.triggerSetAt + this.delay;
    this.i = window.setInterval(this.func, this.delay);
    this.t_restart = null;
    this.paused_timeLeft = 0;
    this.getTimeLeft = function(){
        var now = new Date();
        return this.delay - ((now - this.triggerSetAt) % this.delay);
    }
    this.pause = function(){
        this.paused_timeLeft = this.getTimeLeft();
        window.clearInterval(this.i);
        this.i = null;
    }
    this.restart = function(sender){
        sender.i = window.setInterval(sender.func, sender.delay);
    }
    this.resume = function(){
        if (this.i == null){
            this.i = window.setTimeout(this.restart, this.paused_timeLeft, this);
        }
    }
    this.clearInterval = function(){ window.clearInterval(this.i);}
}
Ceux-ci peuvent être mis en œuvre comme tels:
var pt_hey = new PauseableTimeout(function(){
    alert("hello");
}, 2000);
window.setTimeout(function(){
    pt_hey.pause();
}, 1000);
window.setTimeout("pt_hey.start()", 2000);
Cet exemple définira un délai d'attente (pt_hey) qui est programmé pour alerter, "hey" après deux secondes. Un autre Timeout met pt_hey en pause après une seconde. Un troisième Timeout reprend pt_hey après deux secondes. pt_hey s'exécute pendant une seconde, fait une pause d'une seconde, puis reprend son exécution. pt_hey se déclenche après trois secondes.
Maintenant pour les intervalles plus délicats
var pi_hey = new PauseableInterval(function(){
    console.log("hello world");
}, 2000);
window.setTimeout("pi_hey.pause()", 5000);
window.setTimeout("pi_hey.resume()", 6000);
Cet exemple définit un intervalle de pause (pi_hey) pour écrire "hello world" dans la console toutes les deux secondes. Un timeout met pi_hey en pause après cinq secondes. Un autre délai d'expiration reprend pi_hey après six secondes. Ainsi pi_hey se déclenchera deux fois, fonctionnera pendant une seconde, marquera une pause d'une seconde, fonctionnera pendant une seconde, puis continuera à déclencher toutes les 2 secondes.
 AUTRES FONCTIONS 
- clearTimeout () et clearInterval () - pt_hey.clearTimeout();et- pi_hey.clearInterval();servent de moyen facile d'effacer les délais et les intervalles.
 
- getTimeLeft () - pt_hey.getTimeLeft();et- pi_hey.getTimeLeft();renverra le nombre de millisecondes jusqu'à ce que le prochain déclencheur se produise.