码迷,mamicode.com
首页 > 编程语言 > 详细

[Javascript] Delegate JavaScript (ES6) generator iteration control

时间:2018-02-06 23:00:14      阅读:195      评论:0      收藏:0      [点我收藏+]

标签:const   return   wrap   base   rip   nbsp   dex   ret   div   

We can execute generators from generators, and delegate the iteration control with the yield* keyword.

Yo dawg, I heard you like generators, so I put generators inside your generators.

 

 
function* create3To4Counter() {
    yield 3;
    return 4;
}

function* createCounter() {
    yield 1;
    yield 2;
    const four = yield* create3To4Counter();
    console.log("four", four)
    yield 5;
}

for (let i of createCounter()) {
    console.log(i)
}

/*
1
2
3
4
5
*/

 

[Javascript] Delegate JavaScript (ES6) generator iteration control

标签:const   return   wrap   base   rip   nbsp   dex   ret   div   

原文地址:https://www.cnblogs.com/Answer1215/p/8424212.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!