es6 Generator函数

<script type="text/javascript">

    function* myGenerator(){
        console.log('业务逻辑A')
        let result=yield 'hello'
        console.log(result)
        console.log('业务逻辑B')
        yield 'world'
        console.log('执行完了')
    }

    let mg=myGenerator();
    console.log(mg.next())
    console.log(mg.next('hehe'))
    console.log(mg.next())


</script>

 

posted @ 2020-07-26 10:00  爱跑步的乌龟  阅读(90)  评论(0编辑  收藏  举报