Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

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
Comment

PREVIOUS NEXT
Code Example
Javascript :: java script or js circle collision 
Javascript :: jquery parse url parameters 
Javascript :: array delete 
Javascript :: rows().remove 
Javascript :: array map order by timestamp reactjs 
Javascript :: arrow function vs function in javascript 
Javascript :: javascript get the last item in an array 
Javascript :: angular material moduel 
Javascript :: dayjs dayofyear 
Javascript :: javascript pipe function 
Javascript :: Origin http://localhost:3002 is not allowed by Access-Control-Allow-Origin. 
Javascript :: spread and rest operator javascript 
Javascript :: angular inner page in refresh 404 after ng build 
Javascript :: javascript clear an array 
Javascript :: javascript factory functions 
Javascript :: why my favicon icon is not removing in react 
Javascript :: paper in material ui 
Javascript :: http request body angular 
Javascript :: js get location params 
Javascript :: for check status in ajax javascript 
Javascript :: mui date picker 
Javascript :: esql convert blob to json 
Javascript :: Using redux on react extension 
Javascript :: javascript random number 
Javascript :: linear search javascript 
Javascript :: bootstrap pop modal from another modal 
Javascript :: dynamodb count items node 
Javascript :: display fetch response js 
Javascript :: remove element javascript 
Javascript :: javascript pad string left 
ADD CONTENT
Topic
Content
Source link
Name
9+8 =