Javascript yield from the function nested inside generator

后端 未结 4 933
醉酒成梦
醉酒成梦 2021-01-03 23:55

This code generates an error:

function *giveNumbers() {
    [1, 2, 3].forEach(function(item) {
        yield item;
    })
}

This is probabl

4条回答
  •  情歌与酒
    2021-01-04 00:25

    you can use the yield * syntax.

    function *giveNumbers() {
        yield * [1, 2, 3].map(function(item) {
            return item;
        })
    }
    

提交回复
热议问题