class foo {
constructor() {
console.log('one');
await this.sleep(2000); // <<<
console.log('two');
await this.sleep(2000); // <<<
console.log('three');
}
async sleep(milliseconds) {
const promise = new Promise(resolve => setTimeout(resolve, milliseconds));
return promise;
}
}
new foo();
Uncaught SyntaxError: await is only valid in async functions and the top level bodies of modules