[removed] How do constantly monitor variables value

前端 未结 6 2385
无人共我
无人共我 2021-02-14 08:36

How do I constantly check a variables value. For example:

if(variable == \'value\'){
    dosomething();
}

This would work if I constantly loope

6条回答
  •  生来不讨喜
    2021-02-14 08:50

    As @Pekka commented, you can have a timer constantly poll the variable. A better solution, if it's all your code that's changing the variable, is to not just set the variable directly, but rather have all setters call a function. The function could then set the variable and do any additional processing you need.

    function setValue(value) {
        myVariable = value;
        notifyWatchers();
    }
    

提交回复
热议问题