Skip to content

Commit bad0552

Browse files
committed
docs(async): fix await ruanyf#752
1 parent a67b578 commit bad0552

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

docs/async.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,18 +210,20 @@ getTitle('https://tc39.github.io/ecma262/').then(console.log)
210210

211211
### await 命令
212212

213-
正常情况下,`await`命令后面是一个 Promise 对象。如果不是,会被转成一个立即`resolve`的 Promise 对象
213+
正常情况下,`await`命令后面是一个 Promise 对象。如果不是,就返回对应的值
214214

215215
```javascript
216216
async function f() {
217+
// 等同于
218+
// return 123;
217219
return await 123;
218220
}
219221

220222
f().then(v => console.log(v))
221223
// 123
222224
```
223225

224-
上面代码中,`await`命令的参数是数值`123`它被转成 Promise 对象,并立即`resolve`
226+
上面代码中,`await`命令的参数是数值`123`这时等同于`return 123`
225227

226228
`await`命令后面的 Promise 对象如果变为`reject`状态,则`reject`的参数会被`catch`方法的回调函数接收到。
227229

0 commit comments

Comments
 (0)