1// for async
2const AsyncFunction = Object.getPrototypeOf(async function(){}).constructor;
3// assume someAsyncCall is a call to another async func we await for that returns 1 (just make this simpler)
4const func = new AsyncFunction('arg1', 'arg2', 'return arg1 * arg2 * await someAsyncCall();');
5// now use the function, assuming we are in an async function for the following to work
6await func(2,2); // => 4
7
8
9// for normal non-async functions it's simpler just use the Function constructor
10const func = new Function('arg1', 'arg2', 'return arg1 * arg2;');
11// now use the function
12func(2,2); // => 4