What are ES6 generators and how can I use them in node.js?

前端 未结 5 1617
挽巷
挽巷 2020-12-14 02:50

I was at a node.js meetup today, and someone I met there said that node.js has es6 generators. He said that this is a huge improvement over callback style programming, and w

5条回答
  •  旧时难觅i
    2020-12-14 03:20

    To use the ES6 generators in node, you will need to either install node >= 0.11.2 or iojs.

    In node, you will need to reference the harmony flag:

    $ node --harmony app.js 
    

    or you can explicitly just reference the generators flag

    $ node --harmony_generators app.js
    

    If you've installed iojs, you can omit the harmony flag.

    $ iojs app.js
    

    For a high level overview on how to use generators, checkout this post.

提交回复
热议问题