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

251
Views
Why is an instance of a class not accessible by window in the browser when using modules?

Say I have an HTML file that looks like this:

<body>
    <script>
        class InlineClass {
            constructor(){
                this._title = 'Im inline javascript';
            }
        }

        const myInlineClass = new InlineClass();
    </script>
    <script src="./external.js"></script>
    <script type="module" src="./index.js"></script>
</body>

I have 3 main classes. You can see InlineClass above.

Inside external.js I have the following:

class ExternalFile{
    constructor(){
        this._title = 'Im an external javascript file';
    }
}

const myExternal = new ExternalFile();

And finally, my last example consists of index.js

import ModuleFile from "./module.js";

const myModule = new ModuleFile();

and module.js

class ModuleFile{
    constructor(){
        this._title = 'Im a module';
    }
}

export default ModuleFile;

Why is the module the only instance of a class that isn't accessible to the window object? Here's a screenshot of my console.

Console

I've ruled out any potential CORS issues by adding a console.log to index.js which then lets me see it.

consoleLog

So what exactly is going on here? Why do I get different results?

about 4 years ago · Juan Pablo Isaza
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!