I use the next code for watch changes in javascript object: https://gist.github.com/eligrey/384583
I have a next code for check updates:
var Obj = {
prop: 0,
inc: function() {
this.prop ++;
}
};
Obj.watch('prop', function(prop, oldv, newv) {
console.log(prop);
console.log(oldv);
console.log(newv);
});
// on button click i increment prop:
$("#btn").on('click', function() {
Obj.inc();
});
When i run this code, and click button i get in console:
prop
0
1
It's correctly.
But, when i click the next time, i get:
z
undefined
NaN
Online demo: http://jsbin.com/jenarapufo/2/edit?html,js,console,output
Why?
watchcallback addreturn newv;