Can async/await be used in constructors?

前端 未结 4 1690
时光取名叫无心
时光取名叫无心 2020-12-14 16:21

As the question stated. Will I be allowed to do this:

class MyClass {
    async constructor(){
        return new Promise()
    }
}
4条回答
  •  无人及你
    2020-12-14 16:49

    In a nutshell:

    1. Constructor is a function that needs to provide a concrete object.
    2. Async returns a promise; exactly opposite of concreteness.
    3. async constructor is conceptually conflicting.

提交回复
热议问题