每次变量变化时如何在JavaScript中运行函数?

问题描述:

JavaScript中是否有类似于侦听变量中的变化的事件?所以当它的值被修改时,事件触发,然后我可以调用一个函数。为了更好地理解上下文,我有一个处理对象数组的html呈现的函数,并且我希望每次修改数组时都会自动调用该函数。

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.

感谢。

使用 object.watch docs ,如果本机不支持在这个实现中:所有浏览器的Object.watch()?