标签:apr prot ++ ring return rda 相等 equal str
<script>
var a = {
name: ‘jk‘,
age: 12,
say: {
today: ‘hi‘,
yesterday: ‘no‘
},
arr: [1,2]
};
var b = {
name: ‘jk‘,
age: 12,
say: {
today: ‘hi‘,
yesterday: ‘no‘
},
arr: [1,2]
};
console.log(isObjectValueEqual(a, b));
function isObjectValueEqual(a, b) {
if (typeof a == ‘number‘ && typeof b == ‘number‘) {
return a == b
}
var aProps = Object.getOwnPropertyNames(a);
var bProps = Object.getOwnPropertyNames(b);
if (aProps.length != bProps.length) {
return false;
}
for (var i = 0; i < aProps.length; i++) {
var propName = aProps[i];
console.log(propName, Object.prototype.toString(a[propName]));
//if (Object.prototype.toString(a[propName]) == ‘[Object Object]‘ || Object.prototype.toString(b[propName]) == ‘[Object Object]‘) {
if ( typeof a[propName] === ‘object‘ || typeof b[propName] === ‘object‘ ){
console.log(a[propName], b[propName]);
isObjectValueEqual(a[propName], b[propName])
}else if (a[propName] !== b[propName]) {
return false;
}
}
return true;
}
</script>
标签:apr prot ++ ring return rda 相等 equal str
原文地址:http://www.cnblogs.com/mazhaokeng/p/7058027.html