javascriptでの継承例コード

632 ワード

 
  
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); //
alert(" :"+triangle.silders);
alert(" :"+triangle.getArea());