javascript - JS: EcmaScript6 how to pass different number of parameters to extended class -
i'm having little problem class. got easy, cant find out solution. class cuboid works well, class cube not okey, think i've used super method in wrong way.
just give me little hint. thank in advance.
class cuboid { constructor(length, width, height) { this.length = length; this.width = width; this.height = height; } surfacearea() { return (this.length * this.width + this.length * this.height + this.height * this.width) * 2; } volume() { return this.length * this.width * this.height; } } class cube extends cuboid { constructor(length) { super(length); this.height = length; } } guys, why downvote question? it's not nice...
as suggesting cube cuboid 3 dimension equal. there 2 options it:
1.
class cube extends cuboid { constructor(length) { super(length, length, length); } } 2.
class cuboid { constructor(length, width, height) { this.length = length || 0; this.width = width || this.length; this.height = height || this.width; } // ....
Comments
Post a Comment