Object.watch() for all browsers?

前端 未结 8 741
囚心锁ツ
囚心锁ツ 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:19

    That plugin simply uses a timer/interval to repeatedly check for changes on an object. Maybe good enough but personally I would like more immediacy as an observer.

    Here's an attempt at bringing watch/unwatch to IE: http://webreflection.blogspot.com/2009/01/internet-explorer-object-watch.html.

    It does change the syntax from the Firefox way of adding observers. Instead of :

    var obj = {foo:'bar'};
    obj.watch('foo', fooChanged);
    

    You do:

    var obj = {foo:'bar'};
    var watcher = createWatcher(obj);
    watcher.watch('foo', fooChanged);
    

    Not as sweet, but as an observer you are notified immediately.

提交回复
热议问题