Summary of timer usage in js

The difference between the two methods of creating a timer:

setTimeout only executes function(){} once

setInterval will be executed every interval time until the timer closes

//创建定时器方法
var time1 = window.setTimeout(function(){},interval);
var time2 = window.setInterval(function(){},interval);

//清除定时器方法
window.clearTimeout(time1);
window.clearTimeout(time2);

There is no difference between the two methods of closing the timer, but after the timer is clear, the return values ​​time1 and time2 defined when the timer is created are not cleared. If a new timer is defined, the return value is 3

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325808633&siteId=291194637