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

124
Vistas
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 Respuestas
Responde la pregunta

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 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