how to create dynamic function in javascript code example
Example 1: dynamically generate multiple functions javascript
var f = new Function('name', 'return alert("hello, " + name + "!");');
f('erick');
Example 2: how to create a dynamic function in javascript
const AsyncFunction = Object.getPrototypeOf(async function(){}).constructor;
const func = new AsyncFunction('arg1', 'arg2', 'return arg1 * arg2 * await someAsyncCall();');
await func(2,2);
const func = new Function('arg1', 'arg2', 'return arg1 * arg2;');
func(2,2);