Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

378
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda