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!
How can I track changes of multiple variables at once in JavaScript without using a framework?
-
- Messages : 2
- Enregistré le : 02 juin 2025, 03:58
- Contact :
-
- Messages : 1
- Enregistré le : Hier, 09:14
Re: How can I track changes of multiple variables at once in JavaScript without using a framework?
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.
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.