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

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

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