add: 宏任务和微任务

This commit is contained in:
qianguyihao
2021-05-27 21:56:03 +08:00
parent 48a1ab234f
commit 61d56437eb
23 changed files with 185 additions and 23 deletions

View File

@@ -94,3 +94,31 @@ a成功
b成功
b接口返回的内容
```
### 题目 3
举例1
```js
new Promise((resolve, reject) => {
resolove();
console.log('promise1'); // 代码1
}).then(res => {
console.log('promise then)'; // 代码2微任务
})
console.log('千古壹号'); // 代码3
```
打印结果
```
promise1
千古壹号
promise then
```
代码解释代码1是同步代码所以最先执行代码2是**微任务**里面的代码所以要先等同步任务代码3先执行完
当写完`resolove();`之后就会立刻把 `.then()`里面的代码加入到微任务队列当中