File tree Expand file tree Collapse file tree 1 file changed +1
-1
lines changed Expand file tree Collapse file tree 1 file changed +1
-1
lines changed Original file line number Diff line number Diff line change @@ -259,7 +259,7 @@ b.next(12) // { value:8, done:false }
259
259
b .next (13 ) // { value:42, done:true }
260
260
```
261
261
262
- 上面代码中,第二次运行` next ` 方法的时候不带参数,导致 y 的值等于` 2 * undefined ` (即` NaN ` ),除以 3 以后还是` NaN ` ,因此返回对象的` value ` 属性也等于` NaN ` 。第三次运行` Next ` 方法的时候不带参数,所以` z ` 等于` undefined ` ,返回对象的` value ` 属性等于` 5 + NaN + undefined ` ,即` NaN ` 。
262
+ 上面代码中,第二次运行` next ` 方法的时候不带参数,导致 y 的值等于` 2 * undefined ` (即` NaN ` ),除以 3 以后还是` NaN ` ,因此返回对象的` value ` 属性也等于` NaN ` 。第三次运行` next ` 方法的时候不带参数,所以` z ` 等于` undefined ` ,返回对象的` value ` 属性等于` 5 + NaN + undefined ` ,即` NaN ` 。
263
263
264
264
如果向` next ` 方法提供参数,返回结果就完全不一样了。上面代码第一次调用` b ` 的` next ` 方法时,返回` x+1 ` 的值` 6 ` ;第二次调用` next ` 方法,将上一次` yield ` 表达式的值设为` 12 ` ,因此` y ` 等于` 24 ` ,返回` y / 3 ` 的值` 8 ` ;第三次调用` next ` 方法,将上一次` yield ` 表达式的值设为` 13 ` ,因此` z ` 等于` 13 ` ,这时` x ` 等于` 5 ` ,` y ` 等于` 24 ` ,所以` return ` 语句的值等于` 42 ` 。
265
265
You can’t perform that action at this time.
0 commit comments