File tree Expand file tree Collapse file tree 1 file changed +4
-4
lines changed Expand file tree Collapse file tree 1 file changed +4
-4
lines changed Original file line number Diff line number Diff line change @@ -667,7 +667,7 @@ log(g());
667
667
668
668
## Generator.prototype.return()
669
669
670
- Generator 函数返回的遍历器对象,还有一个` return ` 方法,可以返回给定的值,并且终结遍历 Generator 函数。
670
+ Generator 函数返回的遍历器对象,还有一个` return() ` 方法,可以返回给定的值,并且终结遍历 Generator 函数。
671
671
672
672
``` javascript
673
673
function * gen () {
@@ -683,9 +683,9 @@ g.return('foo') // { value: "foo", done: true }
683
683
g .next () // { value: undefined, done: true }
684
684
```
685
685
686
- 上面代码中,遍历器对象` g ` 调用` return ` 方法后,返回值的` value ` 属性就是` return ` 方法的参数` foo ` 。并且,Generator 函数的遍历就终止了,返回值的` done ` 属性为` true ` ,以后再调用` next ` 方法,` done ` 属性总是返回` true ` 。
686
+ 上面代码中,遍历器对象` g ` 调用` return() ` 方法后,返回值的` value ` 属性就是` return() ` 方法的参数` foo ` 。并且,Generator 函数的遍历就终止了,返回值的` done ` 属性为` true ` ,以后再调用` next() ` 方法,` done ` 属性总是返回` true ` 。
687
687
688
- 如果` return ` 方法调用时,不提供参数,则返回值的` value ` 属性为` undefined ` 。
688
+ 如果` return() ` 方法调用时,不提供参数,则返回值的` value ` 属性为` undefined ` 。
689
689
690
690
``` javascript
691
691
function * gen () {
@@ -700,7 +700,7 @@ g.next() // { value: 1, done: false }
700
700
g .return () // { value: undefined, done: true }
701
701
```
702
702
703
- 如果 Generator 函数内部有` try...finally ` 代码块,且正在执行` try ` 代码块,那么` return ` 方法会导致立刻进入` finally ` 代码块,执行完以后,整个函数才会结束。
703
+ 如果 Generator 函数内部有` try...finally ` 代码块,且正在执行` try ` 代码块,那么` return() ` 方法会导致立刻进入` finally ` 代码块,执行完以后,整个函数才会结束。
704
704
705
705
``` javascript
706
706
function * numbers () {
You can’t perform that action at this time.
0 commit comments