日期:2014-05-16 浏览次数:20485 次
var oldObj = {key:old[]} , newObj = {key:new[]} ;
//如果 newObj{new[]} 不等于 oldObj {old[]} 取出 key
var equal = function(o1, o2){
//null undefined NaN Number Date String Array Object RegExp 本函数只判断了这些类型
//Function Math Element 这些类型不做判断
var b;
if(o1 == null && o1 === o2) return true;
if(o1 == null
------解决方案--------------------
o2 == null) return false;
if(o1.constructor != o2.constructor) return false;
if(o1 instanceof Date
------解决方案--------------------
o1.constructor == Number) return o1 - o2 == 0;
if(o1 instanceof Array){
b = o1.length == o2.length;
if(b)for(var i = o1.length - 1; i >= 0; i--){
if(!b) return b;
b = b && equal(o1[i], o2[i])
}
return b
}
if(o1.constructor == String) return o1.localeCompare(o2) == 0;
if(o1 instanceof RegExp) return o1.source == o2.source && o1.global == o2.global && o1.ignoreCase == o2.ignoreCase && o1.multiline == o2.multiline;
var k1 = [], k2 = [];
for(var p in o1) if(o1.hasOwnProperty(p)) k1.push(p);
for(var p in o2) if(o2.hasOwnProperty(p)) k2.push(p);
b = k1.length == k2.length;
if(b)for(var i = k1.length - 1; i >= 0; i--){
if(!b) return b;
b = b && equal(o1[k1[i]], o2[k2[i]])
}
return b;
},
distinct = function(o1, o2){
var b = [], t = {};
if(typeof o1 != 'object'
------解决方案--------------------
typeof o2 != 'object') return b;
var k1 = [], k2 = [];
for(var p in o1) if(!(o1[p] instanceof Function)) k1.push(p);
for(var p in o2) if(!(o2[p] instanceof Function)) k2.push(p);
for(var i