Skip to content

Commit e3bcf8c

Browse files
committed
Async/Await are even cleaner than Promises
1 parent 4b5192b commit e3bcf8c

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

README-zh-CN.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1940,14 +1940,18 @@ require('request-promise').get('https://en.wikipedia.org/wiki/Robert_Cecil_Marti
19401940
```
19411941
**[⬆ 返回顶部](#代码整洁的-javascript)**
19421942

1943-
### Async/Await are even cleaner than Promises
1943+
### Async/Await Promises 更加简洁
19441944
Promises are a very clean alternative to callbacks, but ES2017/ES8 brings async and await
19451945
which offer an even cleaner solution. All you need is a function that is prefixed
19461946
in an `async` keyword, and then you can write your logic imperatively without
19471947
a `then` chain of functions. Use this if you can take advantage of ES2017/ES8 features
19481948
today!
19491949

1950-
**Bad:**
1950+
Promises 是回调的一个非常简洁的替代品, 但是 ES2017/ES8 带来的 async 和 await 提供了一个
1951+
更加简洁的解决方案。 你需要的只是一个前缀为 `async` 关键字的函数, 接下来就可以不需要 `then`
1952+
函数链来编写逻辑了。 如果你能使用 ES2017/ES8 的高级功能的话, 今天就使用它吧!
1953+
1954+
**不好的:**
19511955
```javascript
19521956
require('request-promise').get('https://en.wikipedia.org/wiki/Robert_Cecil_Martin')
19531957
.then((response) => {
@@ -1962,7 +1966,7 @@ require('request-promise').get('https://en.wikipedia.org/wiki/Robert_Cecil_Marti
19621966

19631967
```
19641968

1965-
**Good**:
1969+
**好的:**
19661970
```javascript
19671971
async function getCleanCodeArticle() {
19681972
try {

0 commit comments

Comments
 (0)