草庐IT

tone-generator

全部标签

5.2 ES6 Generator 函数

ES6新引入了Generator函数,可以通过yield关键字,把函数的执行流挂起,为改变执行流程提供了可能,从而为异步编程提供解决方案。基本用法Generator函数组成Generator有两个区分于普通函数的部分:一是在function后面,函数名之前有个*;函数内部有yield表达式。其中*用来表示函数为Generator函数,yield用来定义函数内部的状态。function*func(){console.log("one");yield'1';console.log("two");yield'2';console.log("three");return'3';}执行机制调用Gener

5.2 ES6 Generator 函数

ES6新引入了Generator函数,可以通过yield关键字,把函数的执行流挂起,为改变执行流程提供了可能,从而为异步编程提供解决方案。基本用法Generator函数组成Generator有两个区分于普通函数的部分:一是在function后面,函数名之前有个*;函数内部有yield表达式。其中*用来表示函数为Generator函数,yield用来定义函数内部的状态。function*func(){console.log("one");yield'1';console.log("two");yield'2';console.log("three");return'3';}执行机制调用Gener