How can I write a generator in a JavaScript class?

后端 未结 3 491
囚心锁ツ
囚心锁ツ 2020-12-28 13:04

Usually, I write code like this:

//definition
exports.getReply = function * (msg){
    //...
    return reply; 
}
//usage
var msg = yield getReply (\'hello\'         


        
3条回答
  •  情话喂你
    2020-12-28 13:37

    TL; DR for confused visitors from Google:

    In Javascript, how do I write a generator function in a class?

    class A {
        * values() {
            yield "a value";
            yield* [1, 2, 3, 4, 5];
        }
    }
    

    is syntactically correct. It works. You’re welcome and now dismissed.

提交回复
热议问题