The following is a printout of the javascript code contained in this page followed by a series of expressions using the code and their values. Enjoy!
$interface("Shape", {
getPerimeter: function() {
return Number();
},
getArea: function() {
return Number();
}
});
$class("Rectangle", {
$implements: Shape,
Rectangle: function(width, height) {
this._width = width;
this._height = height;
},
getWidth: $final(function() {
return this._width;
}),
getHeight: $final(function() {
return this._height;
}),
getPerimeter: function() {
return this.getWidth() * 2 + this.getHeight() * 2;
},
getArea: function() {
return this.getWidth() * this.getHeight();
}
});
$class("Square", {
$extends: Rectangle,
Rectangle: function(width) {
this.$base(width, width);
}
});