On 2006-09-22 16:09:32 +0200, Patient Guy <sevisen.adam@gmailDOTHEREcomsaid:
>
Subject line would seem to say it all:
How does one trigger the execution of a method within an object or any
other code/function with the setting of an object property?
The watch method seems to be just what you want. It is a native method
of the Object object, therefore "inherited" by every JavaScript object.
I haven't tested it, but you should be able to do this :
anObjectType.description="some initial value"
anObjectType.reconstruct = function (prop,oldval,newval)
{
... code that rebuilds the object ...
if(newval is a valid description)
return newval
return oldval
}
anObjectType.watch("description", anObjectType.reconstruct)
The function passed to the watch() method will be executed whenever the
object's property named "description" is modified. That function will
be passed 3 arguments : the name of the property, its current value,
and the value that is about to be assigned to it.
Instead, the return value of the function will be assigned to the propoerty.
here anyway.
--
David Junger