METHOD: Object::watch
Object.watch(property, handlerfunction)
The watch method is inherited by every object descended from Object and
adds a watchpoint to a property of the method. Whenever a value
is assigned to it, it calls up a function allowing you
to watch any new value assigned and, if necessary, alter it.
For example, this following code watches the 'name' property of the 'city' object, and
if the name 'Leningrad' is assigned to it, it is altered to the city's new name of
'St. Petersburg'.
Note the code that is enclosed in the pair of curly braces (an if statement)
which is associated with the handlerfunction argument called 'myfunction':
Code:
city = {name:"Chicago"}
city.watch("name", myfunction (property, oldval, newval)
{
if(newval == "Leningrad")
newval = "St. Petersburg"
return newval
}
) //end of watch method
NOTE:
A watchpoint for a property does not disappear if that property is deleted. It can,
however, be removed by using the unwatch method.
|