Execute top-level JavaScript function inside an arrow function [duplicate]
Solution 1:
I think another way to word your question might be: "How can I access scoped variables using strings?", and the answer is "It's not possible in JavaScript".
If you truly need this kind of dynamic flexibility with your values, you must assign them all to a top-level object (and you must export that object from your module if you want to access it and its values outside the module). Or use eval
, if supported in your environment.
Solution 2:
There is no such object for modules. The module scope is like a function scope - an environment record that you cannot access from javascript, you can only use it to declare variables.
There is an object that holds all the export
ed names of a module (which you can get by doing a namespace import * as … from …
), but this doesn't seem to be what you want.