js 讀書筆記1---對象比較

<html>
<script language="JavaScript"> 
var object1 = {value: 10};
var object2 = object1;
var object3 = {value: 10};
alert(object1 == object2);

alert(object1 == object3);

object1.value = 15;
alert(object2.value);
alert(object3.value);
</script>
</html>


 

object1 and object2 are two variables grasping the same value. There is only one actual object, which is why changing object1 also changes the value of object2. The variable object3 points to another object, which initially contains the same properties as object1, but lives a separate life.

JavaScript's == operator, when comparing objects, will only return true if both values given to it are the precise same value. Comparing different objects with identical contents will give false.

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章