1 | initial version |
One can obtain the function-object of a JavaScript function that is identified by its name in string format using the following methods:
const myFunc = function() {
console.log('Hello World!');
}
const funcName = 'myFunc';
const myFuncObj = window[funcName];
const myFunc = function() {
console.log('Hello World!');
}
const funcName = 'myFunc';
const myFuncObj = eval(funcName);
It is important to note that using eval is not recommended as it can be a security risk, and should only be used when there is no other alternative.