开发者

Do I have to clear setTimeouts after they've run?

Simple question really, I'm running a bunch of timeouts but wanna make sure they don't slow the page down and that for some reason they aren't kept in memory after they've executed.

$projects.each(function(index) {
    var $this = $(this);
    window.setTimeout(function() {
        // animate
    }, 300 * inde开发者_运维问答x);
});
// Clear timeouts?

My guess is that they're destroyed once they've run but just want to follow best practice.


No, you don't. Interval timers (via "setInterval()"), yes, if you want them to stop.

It's harmless to clear a timeout that doesn't have to be cleared. That is, if you do clear one after it has run, browsers won't complain.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜