title: Listener for property value changes in a Javascript object
body: <p>Going through Javascript documentation, I found the following two functions on a Javascript object looks interesting:</p>
  <p><a href="https://developer.mozilla.org/en-US/docs/Archive/Web/JavaScript/Object.watch" rel="noreferrer"><code>.watch</code></a> - Watches for a property to be assigned a value and runs a function when that occurs.<br />
  <code>.unwatch</code> - Removes a watchpoint set with the watch method.</p>
  <hr />
  <blockquote>
  <p><strong>UPDATE</strong>: <strong>Deprecation warning</strong><br>
  Do not use <code>watch()</code> and <code>unwatch()</code>! These two
  methods were implemented only in <em>Firefox</em> prior to version <code>58</code>, they're
  deprecated and removed in <em>Firefox</em> <code>58+</code></p>
  </blockquote>
  <hr />
  <p>Sample usage:</p>
  <pre><code>o = { p: 1 };
  o.watch(&quot;p&quot;, function (id,oldval,newval) {
      console.log(&quot;o.&quot; + id + &quot; changed from &quot; + oldval + &quot; to &quot; + newval)
      return newval;
  });
  </code></pre>
  <p>Whenever we change the property value of &quot;p&quot;, this function gets triggered.<br/></p>
  <pre><code>o.p = 2;   //logs: &quot;o.p changed from 1 to 2&quot;
  </code></pre>
  <p>I am working on Javascript for the past few years and never used these functions.<br />
  Can someone please throw some good use cases where these functions will come in handy?</p>