Object.watch() for all browsers?

前端 未结 8 743
囚心锁ツ
囚心锁ツ 2020-11-22 13:06

Please note that Object.Watch and Object.Observe are both deprecated now (as of Jun 2018).


I was looking for an easy way to monitor an object

8条回答
  •  执笔经年
    2020-11-22 13:37

    Note that in Chrome 36 and higher you can use Object.observe as well. This is actually a part of a future ECMAScript standard, and not a browser-specific feature like Mozilla's Object.watch.

    Object.observe only works on object properties, but is a lot more performant than Object.watch (which is meant for debugging purposes, not production use).

    var options = {};
    
    Object.observe(options, function(changes) {
        console.log(changes);
    });
    
    options.foo = 'bar';
    

提交回复
热议问题