Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

185
Views
What is the name of module scope? How to refer to this scope?

We have a global object in javascript that we can refer to using window for accessing any global variable. But how to refer to the module scope object where all the variables in that module are stored?

Actually, I need to refer to an imported object in the module using string. If it was a global variable, I could've simply done this,

let object_I_want = window[string];

But for module, I can't find the reference for such object. I also tried using this,

var scope = this;

somefunction(){
   let object_I_want = scope[string];
}

But, this is undefined inside module context according to the specification. Is there a way to reference the module scope/module object like window.

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

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.

about 4 years ago · Juan Pablo Isaza Report

0

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 exported 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.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!