File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -1434,7 +1434,7 @@ l.next()
14341434
14351435
14361436
1437- ### 2-55 Syntax(1 )
1437+ ### 2-55 Syntax(1语法 )
14381438
14391439- ` function * loop(){ yield console.log()} `
14401440- 执行一步 : ` const l=loop(); l.next() `
@@ -1468,15 +1468,14 @@ console.log(l.next())
14681468
14691469
14701470
1471- ### 2-56 Syntax(2 )
1471+ ### 2-56 Syntax(2语法 )
14721472
14731473- ` next() ` 传参
14741474 - 参数** 改变** ` yield ` 后面表达式的返回值
14751475 - 不传值 ` yield ` 后面表达式的返回值是 ` undefined `
14761476- ` return() ` 终止
14771477 - 传值则改变 ` yiled ` 后面的表达式 ` value = 参数 `
14781478 - 不传值是 ` undefined `
1479- - 使用错误终止
14801479
14811480``` js
14821481// next() 的返回值
@@ -1491,9 +1490,31 @@ console.log(l.return())
14911490console .log (l .next (20 ))
14921491```
14931492
1493+ - 使用错误终止 ` .throw(new Error('ss')) `
1494+
1495+ ``` js
1496+ // 使用 new Error() 终止循环
1497+ function * gen () {
1498+ while (true ) {
1499+ try {
1500+ yield 1
1501+ } catch (e) {
1502+ console .log (e .message )
1503+ }
1504+ }
1505+ }
1506+ const g = gen ()
1507+ console .log (g .next ())
1508+ console .log (g .next ())
1509+ console .log (g .next ())
1510+ console .log (g .next ())
1511+ g .throw (new Error (' ss' ))
1512+ console .log (g .next ())
1513+ ```
1514+
14941515
14951516
1496- ### 2-57 Scene Pratice
1517+ ### 2-57 Scene Pratice(现场练习)
14971518
14981519```
14991520
You can’t perform that action at this time.
0 commit comments