Given a name (as a string) of a function in the global namespace, the function can be invoked easily. How can the same be achieved for an arrow function?
For instance, how can bar()
be invoked without using eval()
?
function foo(){ console.log("foo"); }
const bar = () => console.log("bar");
window["foo"]();
window["bar"](); // TypeError: window.bar is not a function