doc: add what if section

This commit is contained in:
Leon Xu committed 2021-10-17 12:13:24 -07:00
1 parent a5fac419ad
commit e2ba3444f5
1 file changed
+21 -1
+21 -1
View File
@@ -43,4 +43,24 @@ update: 2021-10-17 11:41:30
}) ();
```
这基本上是同步的,但有点介于两者之间
clickHandler不能保证被调用,所以它被推入异步
clickHandler不能保证被调用,所以它被推入异步
# 如果
我们没有监听事件?
```javascript
let myBtn = qs('button:nth-child(1)');
while (!myBtn.clicked) {
/* Code Here */
}
console.log('"终于等到被点击了"');
let myBtn2 = qs('button:nth-child(2)');
while (!myBtn2.clicked) {
/* Code Here */
}
console.log('"第二次点击"');
```
- 以上的代码没有办法执行(并且会让你的浏览器崩溃)
- 我们在等代码运行的时候什么也做不了
- 但是同步执行逻辑很好