Object.watch() for all browsers?

前端 未结 8 672
囚心锁ツ
囚心锁ツ 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';
    
    0 讨论(0)
  • 2020-11-22 13:38

    I also think that right now the best solution is to use Watch.JS, find a nice tutorial here: Listen/Watch for object or array changes in Javascript (Property changed event on Javascript objects)

    0 讨论(0)
提交回复
热议问题