Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var obj = {};
- obj.a = 1; // fire event, property "a" added
- var checkObj = (function(watchObj)
- {
- var initialMap = {},allProps = [],prop;
- for (prop in watchObj)
- {
- if (watchObj.hasOwnProperty(prop))
- {//make tracer object: basically clone it
- initialMap[prop] = watchObj[prop];
- allProps.push(prop);//keep an array mapper
- }
- }
- return function()
- {
- var currentProps = [];
- for (prop in watchObj)
- {
- if (watchObj.hasOwnProperty(prop))
- {//iterate the object again, compare
- if (watchObj[prop] !== initialMap[prop])
- {//type andvalue check!
- console.log(initialMap[prop] + ' => ' watchObj[prop]);
- //diff found, deal with it whichever way you see fit
- }
- currentProps.push(prop);
- }
- }
- //we're not done yet!
- if (currentProps.length < allProps.length)
- {
- console.log('some prop was deleted');
- //loop through arrays to find out which one
- }
- };
- })(someObjectToTrack);
- var watchInterval = setInterval(checkObj,100);//check every .1 seconds?
Add Comment
Please, Sign In to add comment