• + 0 comments

    super() initializes its parent constructor. In this case it calls constructor of Rectangle. So using super(s,s) will initialize w and h.

    Rectangle.prototype.area = function() {
        return(this.w*this.h);
    };
    
    class Square extends Rectangle {
        constructor(s) {
            super(s,s);
        }
    };
    

    However if you do not provide proper argument to super then you have to manually assign the value of w and h. Like:

    class Square extends Rectangle {
        constructor(s) {
            super()
            this.w = s;
            this.h = s;
        }
    };