function Rectangle(w, h){
this.width = w;
this.height = h;
}
Rectangle.prototype.area = function(){
return this.width * this.height;
}
function PositionedRectangle(w,h,x,y){
Rectangle.call(this, w, h);
this.x = x;
this.y = y;
}
//这里需要显示指定子类的prototype是父类
//因为默认子类的父类是Object
PositionedRectangle.prototype = new Rectangle();
//已经继承了父类的属性,需要删除
delete PositionedRectangle.prototype.width;
delete PositionedRectangle.prototype.height;
PositionedRectangle.prototype.constructor = PositionedRectangle
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/8520577/viewspace-755643/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/8520577/viewspace-755643/