File tree 1 file changed +7
-3
lines changed 1 file changed +7
-3
lines changed Original file line number Diff line number Diff line change @@ -1940,14 +1940,18 @@ require('request-promise').get('https://en.wikipedia.org/wiki/Robert_Cecil_Marti
1940
1940
```
1941
1941
** [ ⬆ 返回顶部] ( #代码整洁的-javascript ) **
1942
1942
1943
- ### Async/Await are even cleaner than Promises
1943
+ ### Async/Await 比 Promises 更加简洁
1944
1944
Promises are a very clean alternative to callbacks, but ES2017/ES8 brings async and await
1945
1945
which offer an even cleaner solution. All you need is a function that is prefixed
1946
1946
in an ` async ` keyword, and then you can write your logic imperatively without
1947
1947
a ` then ` chain of functions. Use this if you can take advantage of ES2017/ES8 features
1948
1948
today!
1949
1949
1950
- ** Bad:**
1950
+ Promises 是回调的一个非常简洁的替代品, 但是 ES2017/ES8 带来的 async 和 await 提供了一个
1951
+ 更加简洁的解决方案。 你需要的只是一个前缀为 ` async ` 关键字的函数, 接下来就可以不需要 ` then `
1952
+ 函数链来编写逻辑了。 如果你能使用 ES2017/ES8 的高级功能的话, 今天就使用它吧!
1953
+
1954
+ ** 不好的:**
1951
1955
``` javascript
1952
1956
require (' request-promise' ).get (' https://en.wikipedia.org/wiki/Robert_Cecil_Martin' )
1953
1957
.then ((response ) => {
@@ -1962,7 +1966,7 @@ require('request-promise').get('https://en.wikipedia.org/wiki/Robert_Cecil_Marti
1962
1966
1963
1967
```
1964
1968
1965
- ** Good ** :
1969
+ ** 好的: **
1966
1970
``` javascript
1967
1971
async function getCleanCodeArticle () {
1968
1972
try {
You can’t perform that action at this time.
0 commit comments