Reputation: 1585
I have got variable e.g. var obj = { foo: 'fooval', bar: 'barval'}
How to write event and trigger to detect any modification of obj
and then call info in console like this: console.log('changed obj.key from oldVal to newVal')
;
Upvotes: 1
Views: 195
Reputation: 77492
There is new feature Object.observe
, NOTE - this feature supported only in Chrome
var obj = { foo: 'fooval', bar: 'barval'};
Object.observe(obj, function(changes) {
console.log(changes);
});
obj.foo = 'bar';
Also there are polyfills, for example Object.observe
Upvotes: 4