基本用法

1
2
3
4
5
6
7
8
9
10
11
function* helloWorldGenerator() {
yield 'hello';
yield 'world';
return 'ending';
}

var hwg = helloWorldGenerator();
hwg.next();//{value: 'hello', done: false}
hwg.next();//{value: 'world', done: false}
hwg.next();//{value: 'ending', done: true}
hwg.nexe();//{value: undefined, done: true}