Listening for variable changes in JavaScript

后端 未结 22 2813
自闭症患者
自闭症患者 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:08

    Sorry to bring up an old thread, but here is a little manual for those who (like me!) don't see how Eli Grey's example works:

    var test = new Object();
    test.watch("elem", function(prop,oldval,newval){
        //Your code
        return newval;
    });
    

    Hope this can help someone

提交回复
热议问题