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

113
Vistas
Detecting changes in a global object using Proxy
    const scopeHandler = {
        set: function(obj, prop, value) {
            console.log(`${prop} changed from ${obj[prop]} to ${value}`);
            obj[prop] = value;
            return true;
        }
    };
    const scopeProxy = new Proxy(window.app, scopeHandler);

So I'm trying to detect any changes whenever app or any of its children app.reports changes, but it doesn't log anything. What am I doing wrong?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

A Proxy will only appear to do anything if the Proxy itself is the value that's "changed" later (via property assignment or whatever traps you have).

If you have an existing object, create a Proxy wrapper for it, and then other parts of an app use the existing object, you won't see anything happen with the Proxy; the other parts of the object would have to have the Proxy instead of the original object.

Here, you might be able to reassign window.app to the Proxy, so that other references to window.app now reference the Proxy instead.

window.app = new Proxy(window.app, scopeHandler);
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