<!-- 學習自javaeye的文章 請轉貼者注自出處 learner:nilinfa -->
<HTML>
<script>
/*定義一個新的對象*/
var emptyObject1 = {};
/*定義一個新的對象*/
var emptyObject2 = new Object();
/*定義一個新的對象,鍵值對應*/
var person = {"name":"sdcst", "age":12, "sex":"male"};
/*彈出兩個新的對象,注意兩種引用方式*/
alert(person.name);
alert(person["age"]);/*注意用[]進行引用時,注意加鍵值雙引號""*/
/*針對新對象進行賦值*/
person.name = "nlf love zhulin";
alert(person.name);
person["age"] = 19;
alert(person.age);
/*以下是刪除對象中的鍵值*/
/*刪除對象name中的鍵值name2*/
delete person.age;
for (var props in person)
{
alert(person[props]);
}
/*對象的constructor屬性*/
var date = new Date();
alert(date.constructor);
alert(date.constructor == "Date"); //false
alert(date.constructor == Date); //true
</script>
</HTML>