Well you can use
Object.watch() property.
But as it is not supported in all browsers u need a
Polyfill to be added to your file.
Apart from these readymade functions you can write your own function using setTimeout() or window.requestAnimationFrame() where you can check the specific property of the function in consecutive threads.
Example :
var threadCheck = requestAnimationFrame ||
webkitRequestAnimationFrame ||
mozRequestAnimationFrame ||
oRequestAnimationFrame ||
msRequestAnimationFrame ||
function(callback) {
setTimeout(callback, 16);
},
oldProperty = {},
watchFunction = function (obj, objProp) {
var len = objProp.length,
prop,
i;
for (i= 0; i < len; i++) {
prop = objProp[i];
oldProperty[prop] = obj[prop];
}
checkFunction();
},
checkFunction = function () {
var prop;
for (prop in oldProperty) {
if (oldProperty[prop] !== obj[prop]) {
executeFunction();
oldProperty[prop] = obj[prop];
}
}
threadCheck(checkFunction);
},
executeFunction = function () {
console.log('changed')
},
obj = {
propertyA : function() {},
propertyB : 'check',
propertyC : {
dummy : 'xyz'
},
propertyD : 999
};
watchFunction(obj, ['propertyA', 'propertyB', 'propertyC', 'propertyD']);
Result(running the given code in the console of chrome browser, it's just a prototype, there are many scopes of improvements. Also unwatch() function has to be implemented):
obj.propertyA = function(){}
(){}
VM1016:35 changed
obj.propertyB = 'check'
"check"
obj.propertyB = 'check1'
"check1"
VM1016:35 changed
obj.propertyB = 'check1'
"check1"
obj.propertyB = 'check2'
"check2"
VM1016:35 changed
obj.propertyA = 'check2'
"check2"
VM1016:35 changed
obj.propertyA = function(){}
(){}
VM1016:35 changed
obj.propertyD = 999
999
obj.propertyD = 99
99
VM1016:35 changed
obj.propertyD = 991
991
VM1016:35 changed