P粉0256324372023-08-23 11:52:11
Update: As others have pointed out, this doesn't really work. @kuboon provided a nice solution below.
You can do this
class Foo { get bar() { return (async () => { return await someAsyncOperation(); })(); } }
This is the same as the code below
class Foo { get bar() { return new Promise((resolve, reject) => { someAsyncOperation().then(result => { resolve(result); }); }) } }