Skip to content

Commit

Permalink
docs(generator): fixed typo
Browse files Browse the repository at this point in the history
  • Loading branch information
ruanyf committed Jul 19, 2024
1 parent 642a4ab commit 1a445ec
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion docs/generator.md
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ b.next(12) // { value:8, done:false }
b.next(13) // { value:42, done:true }
```

上面代码中,第二次运行`next`方法的时候不带参数,导致 y 的值等于`2 * undefined`(即`NaN`),除以 3 以后还是`NaN`,因此返回对象的`value`属性也等于`NaN`。第三次运行`Next`方法的时候不带参数,所以`z`等于`undefined`,返回对象的`value`属性等于`5 + NaN + undefined`,即`NaN`
上面代码中,第二次运行`next`方法的时候不带参数,导致 y 的值等于`2 * undefined`(即`NaN`),除以 3 以后还是`NaN`,因此返回对象的`value`属性也等于`NaN`。第三次运行`next`方法的时候不带参数,所以`z`等于`undefined`,返回对象的`value`属性等于`5 + NaN + undefined`,即`NaN`

如果向`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`

Expand Down

0 comments on commit 1a445ec

Please sign in to comment.