Listening for variable changes in JavaScript

后端 未结 22 3298
自闭症患者
自闭症患者 2020-11-21 06:57

Is it possible to have an event in JS that fires when the value of a certain variable changes? JQuery is accepted.

22条回答
  •  别那么骄傲
    2020-11-21 07:16

    For those tuning in a couple years later:

    A solution for most browsers (and IE6+) is available that uses the onpropertychange event and the newer spec defineProperty. The slight catch is that you'll need to make your variable a dom object.

    Full details:

    http://johndyer.name/native-browser-get-set-properties-in-javascript/

提交回复
热议问题