<html>
<head>
<title>Just Test</title>
<script language="javascript">
//JSON 格式
var o = {
name : "zhouqinsheng",
age : 26,
school : "anhui",
score : {
english : 31,
math : 0
}
};
//Object 格式
var o1 = new Object();
o1.name = "heze";
o1.age = 46;
o1.school = "hunan",
o1.score = new Object();
o1.score.english = 65;
o1.score.math = 1;
//匿名构造器格式
var o2 = new function() {
this.name = "heze";
this.age = 46;
this.school = "hunan",
this.score = new function () {
this.english = 65;
this.math = 2;
};
};
//命名构造器格式
function ClassO() {
this.name = "heze";
this.age = 46;
this.school = "hunan";
function Score() {
this.english = 65;
this.math = 3;
};
this.score = new Score();
};
var o3 = new ClassO();
//基于prototype的命名构造器格式
function ClassOX() {
};
ClassOX.prototype.name = "heze";
ClassOX.prototype.age = 46;
ClassOX.prototype.school = "hunan";
function ScoreX() {
};
ScoreX.prototype.english = 65;
ScoreX.prototype.math = 4;
ClassOX.prototype.score = new ScoreX();
var o4 = new ClassOX();
function show(e) {
alert("name=" + e["name"]
+ "\nage=" + e['age']
+ "\nschool=" + e.school
+ "\nenglish=" + e.score.english
+ "\nmath=" + e.score.math);
};
</script>
</head>
<body onload="show(o);show(o1);show(o2);show(o3);show(o4)">
</body>
</html>