Advertisement
stanevplamen

ES6 JS Classes Inheritance

Sep 23rd, 2022
514
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JavaScript 0.82 KB | Software | 0 0
  1. class Mall {
  2.     constructor(shopname) {
  3.         this.shopname = shopname;
  4.     }
  5.     shopisPresent() {
  6.         return this.shopname +
  7.             ' is present in the  ';
  8.     }
  9. }
  10.  
  11. class Shop extends Mall {
  12.     constructor(name, mallname) {
  13.         super(name);
  14.         this.mallname = mallname;
  15.     }
  16.     showShop() {
  17.         return this.shopisPresent() +
  18.             this.mallname;
  19.     }
  20. }
  21.  
  22. class Kiosk extends Shop {
  23.     constructor(name, mallname) {
  24.         super(name, mallname);
  25.     }
  26.     shopisPresent() {
  27.         return super.shopisPresent() +
  28.             this.mallname + ", pss";
  29.     }
  30. }
  31.  
  32. let newMall = new Shop(
  33.     "Domino", "Select City Walk Mall"
  34. );
  35. let newKiosk = new Kiosk(
  36.     "Domino", "Select City Walk Mall"
  37. );
  38. console.log(newMall.showShop());
  39. console.log(newKiosk.shopisPresent());
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement