Javascript Deep Comparison

后端 未结 3 445
感动是毒
感动是毒 2021-01-21 05:35

Questions about deep comparison of objects have been asked, and I have the solution. But there is a line in the solution that I don\'t completely understand.

This is the

3条回答
  •  北荒
    北荒 (楼主)
    2021-01-21 06:11

    It's checking for existence. It says: "For each property in B, examine A. If A doesn't have the property, or if the value of the property on A doesn't deeply equal the value of the property on B, return false".

    An alternate implementation would avoid the existence check on that line, and instead use if (typeof A == 'undefined') at the top of the function to validate the input parameters at the beginning of each round of recursion...at a glance, I think that'd be equivalent, but less efficient. The current implementation avoids the invocation on the undefined property.

提交回复
热议问题