File tree Expand file tree Collapse file tree 1 file changed +8
-8
lines changed
Expand file tree Collapse file tree 1 file changed +8
-8
lines changed Original file line number Diff line number Diff line change @@ -313,7 +313,7 @@ wrapped().next('hello!')
313313` for...of ` 循环可以自动遍历 Generator 函数时生成的` Iterator ` 对象,且此时不再需要调用` next ` 方法。
314314
315315``` javascript
316- function * foo () {
316+ function * foo () {
317317 yield 1 ;
318318 yield 2 ;
319319 yield 3 ;
@@ -912,16 +912,16 @@ read.next().value // "h"
912912如果被代理的 Generator 函数有` return ` 语句,那么就可以向代理它的 Generator 函数返回数据。
913913
914914``` javascript
915- function * foo () {
915+ function * foo () {
916916 yield 2 ;
917917 yield 3 ;
918918 return " foo" ;
919919}
920920
921- function * bar () {
921+ function * bar () {
922922 yield 1 ;
923- var v = yield * foo ();
924- console .log ( " v: " + v );
923+ var v = yield * foo ();
924+ console .log (" v: " + v);
925925 yield 4 ;
926926}
927927
@@ -1225,7 +1225,7 @@ JavaScript 代码运行时,会产生一个全局的上下文环境(context
12251225Generator 函数不是这样,它执行产生的上下文环境,一旦遇到` yield ` 命令,就会暂时退出堆栈,但是并不消失,里面的所有变量和对象会冻结在当前状态。等到对它执行` next ` 命令时,这个上下文环境又会重新加入调用栈,冻结的变量和对象恢复执行。
12261226
12271227``` javascript
1228- function * gen () {
1228+ function * gen () {
12291229 yield 1 ;
12301230 return 2 ;
12311231}
@@ -1371,7 +1371,7 @@ function scheduler(task) {
13711371``` javascript
13721372let steps = [step1Func, step2Func, step3Func];
13731373
1374- function * iterateSteps (steps ){
1374+ function * iterateSteps (steps ){
13751375 for (var i= 0 ; i< steps .length ; i++ ){
13761376 var step = steps[i];
13771377 yield step ();
@@ -1467,7 +1467,7 @@ gen.next().done // true
14671467Generator 可以看作是数据结构,更确切地说,可以看作是一个数组结构,因为 Generator 函数可以返回一系列的值,这意味着它可以对任意表达式,提供类似数组的接口。
14681468
14691469``` javascript
1470- function * doStuff () {
1470+ function * doStuff () {
14711471 yield fs .readFile .bind (null , ' hello.txt' );
14721472 yield fs .readFile .bind (null , ' world.txt' );
14731473 yield fs .readFile .bind (null , ' and-such.txt' );
You can’t perform that action at this time.
0 commit comments