async constructor javascript
function asyncRequest(id){
return new Promise(/*.....*/);
}
class MyClass {
constructor(async) {
(async function() {
this.city = await asyncRequest(async);
})();
}
}
async constructor javascript
function asyncRequest(id){
return new Promise(/*.....*/);
}
class MyClass {
constructor(async) {
(async function() {
this.city = await asyncRequest(async);
})();
}
}
asynchronous function using function constructor
const AsyncFunction = Object.getPrototypeOf(async function(){}).constructor;
// assume someAsyncCall is a call to another async func we await for that returns 1 (just make this simpler)
const func = new AsyncFunction('arg1', 'arg2', 'return arg1 * arg2 * await someAsyncCall();');
// now use the function, assuming we are in an async function for the following to work
await func(2,2); // => 4
// for normal non-async functions it's simpler just use the Function constructor
const func = new Function('arg1', 'arg2', 'return arg1 * arg2;');
// now use the function
func(2,2); // => 4
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us