Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
async constructors
class Car {
constructor() {
return Promise.resolve(this.new())
}
async new() {
await this.sleep(1000)
this._wheels = 4
return this
}
wheels() {
return this._wheels || 2
}
sleep(ms) {
return new Promise(resolve => {
setTimeout(resolve, ms)
})
}
}
;(async () => {
const car = await new Car()
console.log(car.wheels())
})()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.