Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

265
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda