對事物的抽象描述
描述這類事物的特徵和行為
物件是類別的實例
程式碼實作:建立一個類別
function peple(){ this.hp=0; this.act = 30; this.name = ""; this.x=0; this.y=0; this.move =function(x,y){ document.write(this.name+"正在移动到"+x+","+y); } this.eat=function(){ document.write("正在吃"); } }
類別的實例:建立一個物件
var p1 = new peple(); p1.name="阿达"; p1.hp = 100; p1.move(100,100); p1.move(22,200);
p1.fire = function(x,y){ document.write(this.name+"正在开火向"+x+","+y); p1.hp--; }