File tree Expand file tree Collapse file tree 1 file changed +3
-3
lines changed Expand file tree Collapse file tree 1 file changed +3
-3
lines changed Original file line number Diff line number Diff line change @@ -119,13 +119,13 @@ loader.next()
119
119
120
120
```
121
121
122
- 上面代码表示,第一次调用loadUI函数时,该函数不会执行,仅返回一个遍历器。下一次对该遍历器调用next方法,则会显示Loading界面,并且异步加载数据。再一次使用next方法,则会隐藏Loading界面。可以看到,这种写法的好处是所有Loading界面的逻辑,都被封装在一个函数,按部就班非常清晰。
122
+ 上面代码表示,第一次调用loadUI函数时,该函数不会执行,仅返回一个遍历器。下一次对该遍历器调用next方法,则会显示Loading界面,并且异步加载数据。等到数据加载完成, 再一次使用next方法,则会隐藏Loading界面。可以看到,这种写法的好处是所有Loading界面的逻辑,都被封装在一个函数,按部就班非常清晰。
123
123
124
124
下面是另一个例子,通过Generator函数逐行读取文本文件。
125
125
126
126
``` javascript
127
127
128
- function * numbers () {
128
+ function * numbers () {
129
129
let file = new FileReader (" numbers.txt" );
130
130
try {
131
131
while (! file .eof ) {
@@ -181,7 +181,7 @@ function delay(milliseconds) {
181
181
return deferred .promise ;
182
182
}
183
183
184
- function * f (){
184
+ function * f (){
185
185
yield delay (100 );
186
186
};
187
187
You can’t perform that action at this time.
0 commit comments