<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<title>Ch8_4_1.htm</title>
<script>
function NameCard(name,age,phone,email) {
this.name = name;
this.age = age;
this.phone = phone;
this.email = email;
this.print = printCard;
}
function printCard() {
document.write("姓名 : " + this.name + "<br/>");
document.write("年齡 : " + this.age + "<br/>");
document.write("電話 : " + this.phone + "<br/>");
document.write("電郵 : " + this.email + "<br/><hr/>");
}
</script>
</head>
<body>
<h2>使用建構函數建立物件</h2>
<hr/>
<script>
var objMyCard = new NameCard("陳小安", 20,
"02-22222222","hueyan@ms2.hinet.net");
var objCard = new NameCard(); // 建立物件
objCard.name = "江小魚";
objCard.age = 20;
objCard.phone = "03-33333333";
objCard.email = "hueyan@yahoo.com.tw";
objCard.webaddress1 = "http://www.yahoo.com.tw";
objCard.webaddress2 = "http://www.hinet.net";
objCard.webaddress3 = "http://www.dahan.edu.tw";
objMyCard.print();
objCard.print();
document.write("網址1 : " + objCard.webaddress1 + "<br/><hr/>");
document.write("網址2 : " + objCard.webaddress2 + "<br/><hr/>");
document.write("網址3 : " + objCard.webaddress3 + "<br/><hr/>");
</script>
</body>
</html>