[removed] How do constantly monitor variables value

前端 未结 6 1059
青春惊慌失措
青春惊慌失措 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:40

    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.

提交回复
热议问题