Going through javascript documentation, I found the following two functions on a javascript object looks interesting:
Watch - Watches for a property to be assigned a value and runs a function when that occurs.
Unwatch - Removes a watchpoint set with the watch method.
Sample usage:
o = {p:1}; <br/>
o.watch("p",<br/>
function (id,oldval,newval) {<br/>
document.writeln("o." + id + " changed from " + oldval + " to " + newval)<br/>
return newval;<br/>
}) <br/>
Whenever we change the property value of "p",this function gets triggered.
o.p = 2; //print "o.p changed from 1 to 2"
I am working on javascript for the fast few years and never used these functions.
Can some one please throw some good use cases where these functions will come handy?