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

117
Vistas
Lifetime of a variable inside a function

In the following code, how is it possible that variable temp is still alive after the call to the Decorate ends?

function Decorate(target, key) {
  let temp = target[key];
  Object.defineProperty(target, key, {
    get: function() {
      console.log('getter executed');
      return temp;
    },
    set: function(newValue) {
      console.log('setter executed');
      temp = newValue;
    }
  });
}

class Test {
  x;
  constructor() {}
};

let t = new Test();

Decorate(t, 'x'); //first and only decorator call after which the variable temp should be dead

t.x = 123;  //setter sets x to 123, obviously it somehow still uses temp

t.x = 256;  //second setter call sets x to 256, temp still somehow alive

t.x = 357;  //etc.
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