ES6—42:生成器
发布日期:2021-06-30 15:19:06 浏览次数:2 分类:技术文章

本文共 519 字,大约阅读时间需要 1 分钟。

生成器函数的函数声明与调用

生成器函数的参数传递

生成器函数实例

// 1s后控制台输出111 2s后控制台输出222 3s后控制台输出333function one() {
setTimeout(() => {
console.log(111); iterator.next(); },1000);}function two() {
setTimeout(() => {
console.log(222); iterator.next(); },2000);}function three() {
setTimeout(() => {
console.log(333); iterator.next(); },3000);}function * gen() {
yield one(); yield two(); yield three();}// 获取迭代器对象const iterator = gen();iterator.next();

转载地址:https://jiapy.blog.csdn.net/article/details/114368517 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:ES6—43:Promise
下一篇:ES6—41:迭代器

发表评论

最新留言

哈哈,博客排版真的漂亮呢~
[***.90.31.176]2024年04月07日 05时58分51秒