[removed] How do constantly monitor variables value

前端 未结 6 1031
青春惊慌失措
青春惊慌失措 2021-02-14 08:35

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:45

    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();
    }
    

提交回复
热议问题