Created
October 20, 2018 11:09
-
-
Save oyilmaztekin/e2d32997acfa3812d8340ffcd41e23c4 to your computer and use it in GitHub Desktop.
Revisions
-
oyilmaztekin created this gist
Oct 20, 2018 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,42 @@ class Rectangle { constructor(w, h) { this.w = w; this.h = h; } } Rectangle.prototype.area = function(){ return this.w * this.h } // BAD WAY /* takes first parameter and fill its value in the second h parameter if Square takes second arguments, it will be overriden by the super(h,h) method. it is so dangerous */ // class Square extends Rectangle{ // constructor(h){ // super(h,h) // } // } //CORRECT WAY class Square extends Rectangle { constructor(w,h) { super(w,h) if(!this.h) { this.h = this.w } } } const rec = new Rectangle(3, 4); const sqr = new Square(3); console.log(rec.area()); // it should return 12 console.log(sqr.area()); // it should return 9