[removed] How do constantly monitor variables value

前端 未结 6 2416
无人共我
无人共我 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条回答
  •  猫巷女王i
    2021-02-14 08:53

    This solution use deprecated APIs. Computed properties and proxies are a better alternative except on the oldest browsers. See K2Span's answer for an example of how to use those.

    Object.watch:

    Watches for a property to be assigned a value and runs a function when that occurs.

    Object.watch() for all browsers? talks about cross-browser ways to do Object.watch on browsers that don't support it natively.

提交回复
热议问题