两个JS对象怎样才能相等
在JS中,两个对象如何才能相等?下面的两个 Alert,只有一个输出true. 在JS中如何才能构造出两个JS对象相等?
var prop1 = {asd:{def:'abc'}};
var prop2 = {asd:{def:'abc'}}; alert( prop1==prop2)//false alert( prop1['asd']==prop2['asd'] ) ;//false
alert( prop1['asd']['def']==prop1['asd']['def'] ) ; //true
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML> <HEAD> <TITLE> New Document </TITLE>
<script>
var prop1 = {asd:{def:'abc'}};
var prop2 = {asd:{def:'abc'}}; alert( prop1==prop2)//false alert( prop1['asd']==prop2['asd'] ) ;//false
alert( prop1['asd']['def']==prop1['asd']['def'] ) ; //true
</script>
</HEAD>
<BODY>
</BODY> </HTML>