proposal-async-init
proposal-async-init copied to clipboard
Fourth path, backward compatible
class Query {
constructor(data) {
this.data = data;
}
async then () {
this.somenewdata = await someAsyncFunc();
return this;
}
}
This way await new Query({data: 'helloworld'})
keeps the constructor synchronous, backward compatible, and keep .then working.
This already works right? Thanks for the idea, I'm thinking of implementing it in a project I'm working on.