(ES6) class (ES2017) async / await getter

前端 未结 4 1961
我寻月下人不归
我寻月下人不归 2020-12-08 08:58

Is it or will it be possible to have an ES6 class getter return a value from an ES2017 await / async function.

class Foo {
    async get bar() {
        var          


        
4条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-08 09:40

    You can get the value by await on the caller side.

    class Foo {
        get bar() {
            return someAsyncOperation();
        }
    }
    async function test(){
      let foo = new Foo, val = await foo.bar;
      val.should.equal('baz');
    }
    

提交回复
热议问题