<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<title>Ch8_2_2.htm</title>
</head>
<body>
<h2>使用物件字面值建立物件方法</h2>
<hr/>
<script>
// 建立自訂物件
var objCard = {
name : "陳小安",
age : 20,
phone: "02-22222222",
email: "hueyan@ms2.hinet.net",
printCard: function() {
document.write("姓名 : " + this.name + "<br/>");
document.write("年齡 : " + this.age + "<br/>");
document.write("電話 : " + this.phone + "<br/>");
document.write("電郵 : " + this.email + "<br/>");
}
};
// 呼叫物件方法
objCard.printCard();
</script>
</body>
</html>