- 相關(guān)推薦
Javascript簡(jiǎn)單實(shí)現面向對象編程繼承實(shí)例代碼
復制代碼 代碼如下:
function Polygon(iSliders){ //定義一個(gè)多邊形
this.silders=iSliders;
}
Polygon.prototype.getArea=function(){ //為多邊形定義一個(gè)去的面積的方法
return 0;
}
function Triangle(iBase,iHeight){
Polygon.call(this,3); //繼承多邊形對象
this.base=iBase;
this.height=iHeight;
}
Triangle.prototype.getArea=function(){ //重寫(xiě)去的面積的方法
return 0.5*this.base*this.height;
}
var triangle=new Triangle(15,8); //實(shí)例化一個(gè)三角形
alert("邊數:"+triangle.silders);
alert("面積:"+triangle.getArea());
【Javascript簡(jiǎn)單實(shí)現面向對象編程繼承實(shí)例代碼】相關(guān)文章:
關(guān)jQuery彈出窗口簡(jiǎn)單實(shí)現代碼-javascript編程06-07
JavaScript實(shí)現網(wǎng)頁(yè)刷新代碼段08-07
常用排序算法之JavaScript實(shí)現代碼段06-04
2016年java面向對象編程題庫及答案10-24
在Java中執行JavaScript代碼07-14
JavaScript fontcolor方法入門(mén)實(shí)例07-07
數控編程代碼大全05-18
ASP編程實(shí)例大全05-29