doc: add motivating timerID section

This commit is contained in:
Leon Xu committed 2021-10-03 11:53:46 -07:00
1 parent f41559aefd
commit b4ef62deac
1 file changed
+6 -1
+6 -1
View File
@@ -81,4 +81,9 @@ function repeatedMessage() {
function sayHello() {
id("output-text").textContent += "你好!";
}
```
```
# timerID变量
我们有时需要跟踪我们的计时器(s)当管理它们之间的函数,以便我们可以使用clearInterval/clearTimeout或知道我们是否有一个计时器已经在我们的页面上运行。
当我们不能将它们作为局部变量进行跟踪时,最好将它们存储为模块全局变量(在模块模式的范围内,但可被程序中的所有函数访问)。
为了简洁起见,这些示例将假设我们在模块模式中编写代码,但您可以参考完整的例子。