听取JavaScript中的变量更改
问题描述:
当某个变量的值发生变化时,是否有可能在JS中触发事件? JQuery被接受。
Is it possible to have an event in JS that fires when the value of a certain variable changes? JQuery is accepted.
答
是的, object.watch
(虽然它是非标准的)。 这是我的实施,适用于当前所有主流浏览器。
Yes, object.watch
(it's non-standard though). Here's my implementation that works in every current major browser.