File tree 2 files changed +2
-2
lines changed
2 files changed +2
-2
lines changed Original file line number Diff line number Diff line change @@ -263,7 +263,7 @@ b.next(13) // { value:42, done:true }
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
266
- 注意,由于` next ` 方法的参数表示上一个` yield ` 表达式的返回值,所以第一次使用 ` next ` 方法时,不能带有参数 。V8 引擎直接忽略第一次使用` next ` 方法时的参数,只有从第二次使用` next ` 方法开始,参数才是有效的。从语义上讲,第一个` next ` 方法用来启动遍历器对象,所以不用带有参数。
266
+ 注意,由于` next ` 方法的参数表示上一个` yield ` 表达式的返回值,所以在第一次使用 ` next ` 方法时,传递参数是无效的 。V8 引擎直接忽略第一次使用` next ` 方法时的参数,只有从第二次使用` next ` 方法开始,参数才是有效的。从语义上讲,第一个` next ` 方法用来启动遍历器对象,所以不用带有参数。
267
267
268
268
如果想要第一次调用` next ` 方法时,就能够输入值,可以在 Generator 函数外面再包一层。
269
269
Original file line number Diff line number Diff line change @@ -716,7 +716,7 @@ for (let e in es6) {
716
716
for (let e of es6) {
717
717
console .log (e);
718
718
}
719
- // TypeError: es6 is not iterable
719
+ // TypeError: es6[Symbol.iterator] is not a function
720
720
```
721
721
722
722
上面代码表示,对于普通的对象,` for...in ` 循环可以遍历键名,` for...of ` 循环会报错。
You can’t perform that action at this time.
0 commit comments