I have a js file that exports a function myFunction. Then, I have another function defined outside the exported module. How can I access it dynamically by its name?
I'm trying in this way but it doesn't work:
exports.myFunction = () => {
let functionName = 'helperFunction';
global[functionName]();
}
const helperFunction = () => {
console.log('helperFunction invoked');
}
I'm trying with the global scope global[functionName]();, but doesn't work. What is the scope of the helper function?
The reason why helperFunction is outside the export is because I export multiple functions in the same file that call helperFunction.
TypeError: ["helperFunction"] is not a function