JSFiddle - React, Tailwind, and code Playground
by jq153387
JavaScript
//物件的建構函數
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/>");
}
//建立自訂物件
var objMyCard=new NameCard("王力宏",30,"02-555555555","lee@yahoo.com.tw");
var objCard=new NameCard();
objCard.name="張惠妹";
objCard.age=40;
objCard.phone="02-888888888";
objCard.email="me@gmail.com";
//顯示物件屬性
objMyCard.print();
objCard.print();