function Shape(type) {
this.type = type;
this.area = function ( ) {
return "I have no idea";
}
}
Rectangle.prototype = new Shape("Rectangle"); Rectangle.prototype.constructor = Rectangle;
function Rectangle(w, h) {
this.width = w;
this.height = h;
this.area = function ( ) {
return this.width * this.height;
}
}
Circle.prototype = new Shape("Circle");
Circle.prototype.constructor = Circle;
function Circle(radius) {
// The constructor defines the class itself.
// r is an instance property, defined and initialized in the constructor.
this.r = radius;
this.PI = 3.1415926;
this.area = function ( ) {
return this.PI * this.r * this.r;
}
}
rect = new Rectangle(3,1);
circle = new Circle(3);
shape = new Shape("Shape");
aShape = {"rect":rect,"circle":circle,"shape":shape};
output(aShape);
function output(o) {
for( s in o) {
document.write("type="+o[s].type+"");
document.write("area="+o[s].area()+"");
}
}