Posted on 2007-10-27 00:42
itspy 阅读(3489)
评论(4) 编辑 收藏 所属分类:
小巧实例
在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>