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

125
Visualizações
Assigning local reference to global

here's what I can't understand.

I have this function here

function foo(){
let a = {a:1};
window.a = a; 
}

as you can see, this assign to a an object, so a reference to it, and then it creates a new property on the window object that contains this reference. If the a variable is local, it's reference point to an address in the stack, so, how can I access a from window, also out of the function, when the stack is cleaned?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

If the a variable is local, it's reference point to an address in the stack

No. While a variable might be allocated on a stack containing the reference, what it references (the object) is likely allocated on "the heap", as - as you've noticed - it's lifetime is not known and as such must be managed by the garbage collector and cannot be stack-allocated.

That said the "stack" vs. "heap" distinction is not quite reflecting the reality of modern JIT-compilers.

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