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

387
Vistas
js make later get window variable; don't init var until this var is called

I expect set window variable before its inner class defined, so I make following code

Object.assign(window, {
    get C2() {
        return C
    }
})

class C {

}

new C2()

but it raise Uncaught ReferenceError: Cannot access 'C' before initialization, I know put class C def before Object.assign can fix this err, but my confused is why following code cannot later get

Object.assign(window, {
        get C2() {
            return C
        }
    })
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

The C class you name is actually referenced as soon as you call Object.assign, the get C2() property that is created contains a reference to C that must be known when Object.assign is called.

If the C class name is not known when Object.assign is called, then JS doesn't know what should be assigned.

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