JavaScript

Private Members

//The values of w and h can never be changed after the object is created.
//Constructor:
function ImmutableRectangle (w, h){
    this.getWidth = function() {
        return w;
    };
    this.getHeight = function() {
        return h;
    };
}

//Get values like this.
ImmutableRectangle.prototype.area() = function (){
    return this.getWidth() * this.getHeight();
}

José M. Vidal .

61 of 65