Note that there are some explanatory texts on larger screens.

plurals
  1. POObject.watch() for all browsers?
    primarykey
    data
    text
    <p><strong>Please be sure to read all the comments below. Object.Watch and Object.Observe are both deprecated. See Elliot B's comment for an updated (as of Jun 2018) method.</strong></p> <hr> <p>I was looking for an easy way to monitor an object or variable for changes, and I found <code>Object.watch()</code>, that's supported in Mozilla browsers, but not IE. So I started searching around to see if anyone had written some sort of equivalent. </p> <p>About the only thing I've found has been <a href="http://plugins.jquery.com/watch/" rel="noreferrer">a jQuery plugin</a>, but I'm not sure if that's the best way to go. I certainly use jQuery in most of my projects, so I'm not worried about the jQuery aspect...</p> <p>Anyway, the question: Can someone show me a working example of that jQuery plugin? I'm having problems making it work... </p> <p>Or, does anyone know of any better alternatives that would work cross browser?</p> <p><strong>Update after answers</strong>:</p> <p>Thanks everyone for the responses! I tried out the code posted here: <a href="http://webreflection.blogspot.com/2009/01/internet-explorer-object-watch.html" rel="noreferrer">http://webreflection.blogspot.com/2009/01/internet-explorer-object-watch.html</a></p> <p>But I couldn't seem to make it work with IE. The code below works fine in Firefox, but does nothing in IE. In Firefox, each time <code>watcher.status</code> is changed, the <code>document.write()</code> in <code>watcher.watch()</code> is called and you can see the output on the page. In IE, that doesn't happen, but I can see that <code>watcher.status</code> is updating the value, because the last <code>document.write()</code> call shows the correct value (in both IE and FF). But, if the callback function isn't called, then that's kind of pointless... :)</p> <p>Am I missing something?</p> <pre><code>var options = {'status': 'no status'}, watcher = createWatcher(options); watcher.watch("status", function(prop, oldValue, newValue) { document.write("old: " + oldValue + ", new: " + newValue + "&lt;br&gt;"); return newValue; }); watcher.status = 'asdf'; watcher.status = '1234'; document.write(watcher.status + "&lt;br&gt;"); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload