Does the browser keep track of active timer IDs?

后端 未结 5 1258
没有蜡笔的小新
没有蜡笔的小新 2021-02-05 09:34

Does the browser keep track of active setInterval and setTimeout IDs? Or is this solely up to the developer to keep track of?

If it does keep t

5条回答
  •  生来不讨喜
    2021-02-05 09:58

    Look at the scripts below, the browser could remember the id of each setTimeout iteration

    for (i = 1; i <= d; i++) {
              (function(j) {
                    var delay = j/d; 
                   t[j] = setTimeout(function() {      
                          elem.style.top = j+"px";
                         },delay);
    
                })(i);           
     } 
    

    You can access them by

    for (i in t) {
          alert(t[i]);  
     }
    

提交回复
热议问题