Generator函数
Generator 函数是 ES6 提供的一种异步编程解决方案,语法行为与传统函数完全不同。
function关键字和函数名之间有一个星号。
function* helloWorldGenerator() {
yield 'hello';
yield 'world';
return 'ending';
}
yield
yield表达式就是暂停标志,只有在Generator函数调用next后才会执行后面的表达式。
参考:
阮一峰-ECMAScript 6 入门 https://es6.ruanyifeng.com/