Is there a way in JavaScript to have something like an event that listens to changes in a variable? So when its value is modified, the event triggers and then I can call a function. To put this more into context, I have a function which handles the HTML rendering of an array of objects, and I want that function to be called automatically every time the array is modified.
Share
Update
Since
Object.watchhas been deprecated (since 2018), you should have a look at using aProxyto allow control over when something is getting updated. A good implementation can be found at How to create a Deep Proxy (aka Proxy Membrane)?Original answer
Use
object.watchdocs and if it is not supported natively look at this implementation: Object.watch() for all browsers?