Skip to content

Commit

Permalink
add: JS书籍《JavaScript 悟道》
Browse files Browse the repository at this point in the history
  • Loading branch information
qianguyihao committed Oct 16, 2021
1 parent ec3de70 commit 176e36b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,33 +1,32 @@
---
title: 08-Async Await函数详解
publish: true
---

<ArticleTopAd></ArticleTopAd>




## async/await (异步函数)概述

async/await 是在 ES8(即ES 2017)中引入的新语法,是另外一种异步编程解决方案。

本质: Generator 的语法糖。
本质: Generator 的语法糖。

- async 的返回值是 Promise 实例对象。

- await 可以得到异步结果。

我们在普通的函数前面加上 async 关键字,就成了 async 函数。

什么是语法糖呢?语法糖就是让语法变得更加简洁、更加舒服,有一种甜甜的感觉。

## async/await 的基本用法

async 后面可以跟一个 Promise 实例对象。代码举例如下:

```javascript
const request1 = function() {
const promise = new Promise(resolve => {
request('https://www.baidu.com', function(response) {
request('https://www.baidu.com/xxx_url', function(response) {
if (response.retCode == 200) {
// 这里的 response 是接口1的返回结果
resolve('request1 success'+ response);
Expand Down
6 changes: 6 additions & 0 deletions 17-前端综合/01-2021年Web前端入门自学路线.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,12 @@

红宝书,人人都知道。

- [JavaScript 悟道](https://book.douban.com/subject/35469273/)》

本书首先介绍JavaScript的基本知识:命名、数值、布尔值和字符串等,并展示了其缺陷和局限性,但随后展示了如何解决这些问题;接着继续研究数据结构和函数,探索底层机制,并使用高阶函数来实现面向对象编程。

本书的翻译是@死月,

### 3、CSS相关书籍

- [CSS世界](https://book.douban.com/subject/27615777/)》
Expand Down

0 comments on commit 176e36b

Please sign in to comment.