async constructor function code example
Example 1: js class async constructor
function asyncRequest(id){
return new Paormise(/*.....*/);
}
class MyClass {
constructor(name, age, cityId) {
(async function() {
this.name = name;
this.age = age;
this.city = await asyncRequest(cityId);
})();
}
}
Example 2: async constructor javascript
function asyncRequest(id){
return new Promise(/*.....*/);
}
class MyClass {
constructor(async) {
(async function() {
this.city = await asyncRequest(async);
})();
}
}