- 相關(guān)推薦
Javascript簡單實(shí)現(xiàn)面向?qū)ο缶幊汤^承實(shí)例代碼
復(fù)制代碼 代碼如下:
function Polygon(iSliders){ //定義一個多邊形
this.silders=iSliders;
}
Polygon.prototype.getArea=function(){ //為多邊形定義一個去的面積的方法
return 0;
}
function Triangle(iBase,iHeight){
Polygon.call(this,3); //繼承多邊形對象
this.base=iBase;
this.height=iHeight;
}
Triangle.prototype.getArea=function(){ //重寫去的面積的方法
return 0.5*this.base*this.height;
}
var triangle=new Triangle(15,8); //實(shí)例化一個三角形
alert("邊數(shù):"+triangle.silders);
alert("面積:"+triangle.getArea());
【Javascript簡單實(shí)現(xiàn)面向?qū)ο缶幊汤^承實(shí)例代碼】相關(guān)文章:
數(shù)控編程代碼大全02-13
javascript跨域訪問的方法07-19
原生ajax調(diào)用數(shù)據(jù)實(shí)例簡單講解07-19
Java代碼的基本知識09-03
PHP Socket編程過程02-09
數(shù)控機(jī)床編程步驟11-08
硬盤邏輯故障解決方法實(shí)例07-16