doc: create synchronous and asynchronous section
This commit is contained in:
1 parent
1f05120efd
commit
33f8c12238
1 file changed
+23
-1
@@ -20,4 +20,26 @@ update: 2021-10-17 11:41:30
|
||||
我们将函数作为参数传递给其他函数,以便当我们知道预期发生的事情时,可以“稍后回调”。
|
||||
回调在事件驱动编程中是一个非常强大的特性。
|
||||
为什么你认为在JavaScript语言中有能力将回调函数作为参数传递给其他函数,如JS中的addEventListener和setTimeout是有用的?
|
||||

|
||||

|
||||
|
||||
# 同步与异步
|
||||
```javascript
|
||||
(function () {
|
||||
...
|
||||
function init() {
|
||||
console.log('page loaded');
|
||||
qs('button').addEventListener('click', clickHandler);
|
||||
showMenu();
|
||||
}
|
||||
|
||||
function showMenu() {
|
||||
id('menu').classList.remove('hidden');
|
||||
}
|
||||
|
||||
function clickHandler() {
|
||||
/* Code Here */
|
||||
}
|
||||
}) ();
|
||||
```
|
||||
这基本上是同步的,但有点介于两者之间
|
||||
clickHandler不能保证被调用,所以它被推入异步
|
||||
Reference in new issue
Block a user