Page 1 sur 1

How can I track changes of multiple variables at once in JavaScript without using a framework?

Posté : 22 sept. 2025, 10:43
par sophiasmith
Hi everyone,
I’m working on a small project and I want to track multiple variables at the same time. Whenever any of them change, I want to trigger a specific action. I know I could use Proxy or Object.defineProperty, but I’m not sure how to implement it in a clean and efficient way.
Does anyone have experience with this? Is there a pure JavaScript way to “listen” to multiple variables directly without using any frameworks?

Thanks in advance!

Re: How can I track changes of multiple variables at once in JavaScript without using a framework?

Posté : 08 oct. 2025, 09:17
par heelversion
Hey! I’ve played around with something similar in a side project, and yeah—it can get messy fast if you’re not careful 😅

I ended up using a Proxy because it felt cleaner than juggling Object.define Property for each variable. What helped me was wrapping all the variables into a single object and then watching changes through the proxy handler. That way, I could trigger my action whenever any property changed.