Watch
From PlainOldWebserver
watch()
watch() is a wonderful but forgotten function that monitors variables, alerts you of changes, then allows you to back out of changes if you choose. It also allows a chance to change other variables at the same time.
var obj = new Object();
obj.p = 1;
var c = 2;
function handle_p(id,old_val,new_val) {
document.writeln(id+" is now "+new_val);
return new_val;
}
obj.watch("p", handle_p);
watch("c", handle_p);
c = 3;
c = 4;
obj.p = 2;
obj.p = 3;
Result:
c is now 3 c is now 4 p is now 2 p is now 3
