Skip to content

Commit 65f0d9e

Browse files
committed
Merge pull request BonsaiDen#77 from xavierm02/master
Added another way to clear "all" timeouts and replaced the "is is" by "it is".
2 parents 27b4b2f + 0a894c1 commit 65f0d9e

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

doc/en/other/timeouts.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,16 @@ it is necessary to use brute force in order to achieve this functionality.
9494
clearTimeout(i);
9595
}
9696

97-
There might still be timeouts that are unaffected by this arbitrary number;
98-
therefore, is is instead recommended to keep track of all the timeout IDs, so
97+
But there might still be timeouts that are unaffected by this arbitrary number. Another way of doing this is to consider that the ID given to a timeout is incremented by one everytime you call `setTimeout`.
98+
99+
// clear "all" timeouts
100+
var biggestTimeoutId = window.setTimeout(function(){}, 1),
101+
i;
102+
for(i = 1; i <= biggestTimeoutId; i++) {
103+
clearTimeout(i);
104+
}
105+
106+
But even though this works on all main browsers nowadays, it isn't specified that the IDs should be ordered that way and it may change. Therefore, it is instead recommended to keep track of all the timeout IDs, so
99107
they can be cleared specifically.
100108

101109
### Hidden use of `eval`

0 commit comments

Comments
 (0)