Does node.js support yield?

后端 未结 10 667
误落风尘
误落风尘 2021-01-31 01:51

Is there any way to get generators into node.js?

I\'m currently faking them with callbacks, but I have to remember to check the response of the callback inside of my gen

相关标签:
10条回答
  • 2021-01-31 02:51

    We are using gnode for generators in node < 0.11.3 - https://github.com/TooTallNate/gnode

    0 讨论(0)
  • 2021-01-31 02:52

    The issue proposing generatiors in v8 has recently been accepted by v8 project member.
    Please vote there to make yield come true.

    0 讨论(0)
  • 2021-01-31 02:56

    Yes, since version 0.11. Enjoy!

    http://wingolog.org/archives/2013/05/08/generators-in-v8

    http://jlongster.com/A-Study-on-Solving-Callbacks-with-JavaScript-Generators

    0 讨论(0)
  • 2021-01-31 02:56

    You can use generators in Node.js, but only in 0.11+. Node.js 0.12 (stable) is now available. Add --harmony_generators or --harmony to the command line parameters of node to enable it.

    With Traceur, you can compile advanced JavaScript to vanilla JavaScript. You could make a loader for node.js that does this on-the-fly. Since it runs on, and compiles to vanilla JavaScript, it runs in node.js < 0.11 as well as in the browser.

    Facebook has developed a lighter version that only supports generators, called Regenerator. It works similarly to Traceur.

    0 讨论(0)
提交回复
热议问题