Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

116
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!