diff --git a/src/watch.js b/src/watch.js index 0c6dea2..48755c6 100644 --- a/src/watch.js +++ b/src/watch.js @@ -51,17 +51,33 @@ var aplus = [], bplus = []; - if(!(typeof a == "string") && !(typeof b == "string") && !isArray(a) && !isArray(b)){ + if(!(typeof a == "string") && !(typeof b == "string")){ - for(var i in a){ - if(b[i] === undefined){ - aplus.push(i); + if (isArray(a)) { + for (var i=0; i 0)){ - if(level !== undefined){ - level--; - } - watchAll(obj[prop], watcher, level); //recursively watch all attributes of this + watchAll(obj[prop], watcher, level!==undefined? level-1 : level); //recursively watch all attributes of this } - defineWatcher(obj, prop, watcher); + defineWatcher(obj, prop, watcher, level); - if(addNRemove){ + if(addNRemove && (level === undefined || level > 0)){ pushToLengthSubjects(obj, prop, watcher, level); } @@ -233,7 +250,9 @@ } } else { for (var prop2 in obj) { //for each attribute if obj is an object - props.push(prop2); //put in the props + if (obj.hasOwnProperty(prop2)) { + props.push(prop2); //put in the props + } } } @@ -244,11 +263,13 @@ var unwatchMany = function (obj, props, watcher) { for (var prop2 in props) { //watch each attribute of "props" if is an object - unwatchOne(obj, props[prop2], watcher); + if (props.hasOwnProperty(prop2)) { + unwatchOne(obj, props[prop2], watcher); + } } }; - var defineWatcher = function (obj, prop, watcher) { + var defineWatcher = function (obj, prop, watcher, level) { var val = obj[prop]; @@ -262,7 +283,7 @@ obj.watchers[prop] = []; } - for(var i in obj.watchers[prop]){ + for (var i=0; i0)){if(s!==undefined){s--}l(e[t],r,s)}m(e,t,r);if(o){x(e,t,r,s)}};var p=function(){if(n(arguments[1])){d.apply(this,arguments)}else if(i(arguments[1])){v.apply(this,arguments)}else{E.apply(this,arguments)}};var d=function(e,t){if(e instanceof String||!(e instanceof Object)&&!i(e)){return}var n=[];if(i(e)){for(var r=0;r0)){l(e[t],r,s!==undefined?s-1:s)}m(e,t,r,s);if(o&&(s===undefined||s>0)){x(e,t,r,s)}};var p=function(){if(n(arguments[1])){d.apply(this,arguments)}else if(i(arguments[1])){v.apply(this,arguments)}else{E.apply(this,arguments)}};var d=function(e,t){if(e instanceof String||!(e instanceof Object)&&!i(e)){return}var n=[];if(i(e)){for(var r=0;r