我正在检查这个问题Javascript深度比较 问题提问者的解决方案没有说服我所以我试图分析问题并提出了
var obj = {here: 2};
console.log(deepEqual(obj, obj));
// ? true
console.log(deepEqual(obj, {here: 1}));
// ? false
console.log(deepEqual(obj, {here: 2}));
// ? true
function deepEqual(a,b)
{
if( (typeof a == 'object' && a != null) &&
(typeof b == 'object' && b != null) )
{
var count = [0,0];
for( var key in a) count[0]++;
for( var key in b) count[1]++;
if( count[0]-count[1] != 0) {console.log('1');return false;}
for( var key in a)
{
if(!(key in b) || …Run Code Online (Sandbox Code Playgroud)