I have an object that I created previously.
obj = new Object();
I would like to fire a function each time this one of the object child is changed.
ex:
function changed()
{
alert('Object changed';)
}
obj.test = 'blabla'; //fire changed().
Is this possible? Thank you
Yes and no. What you’re looking for are accessors and mutators (also known as getters and setters), but unfortunately they’re not cross-browser compatible.
If you just need to notice that the value has changed, and delays aren’t an issue, you could use a timeout loop for polling the value:
This is, of course, a very simple example of how a polling loop could work. There are better ways of doing this.