Listen a property for changes

by Mohan 2012-09-20 23:20:37



Listen a property for changes
function onFooChange( id, oldval, newval ) {

Print( id + " property changed from " + oldval + " to " + newval );
return newval;
}

var o = { foo:5 };
o.watch( 'foo', onFooChange );

o.foo = 6;

delete o.foo;

o.foo = 7;

o.unwatch('foo');
o.foo = 8;
prints:
foo property changed from 5 to 6
foo property changed from undefined to 7

684
like
0
dislike
0
mail
flag

You must LOGIN to add comments