You are viewing a single comment's thread. Return to all 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; } };
Seems like cookies are disabled on this browser, please enable them to open this website
An unexpected error occurred. Please try reloading the page. If problem persists, please contact support@hackerrank.com
Day 5: Inheritance
You are viewing a single comment's thread. Return to all comments →
super() initializes its parent constructor. In this case it calls constructor of Rectangle. So using super(s,s) will initialize w and h.
However if you do not provide proper argument to super then you have to manually assign the value of w and h. Like: