Advertisement
Guest User

4. The Elemelons

a guest
Nov 6th, 2016
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function arr() {
  2.     class Melon {
  3.         constructor(weight, melonSort) {
  4.             if (new.target === Melon)
  5.                 throw new TypeError(`Abstract class cannot be instantiated directly`);
  6.             this.weight = weight;
  7.             this.melonSort = melonSort;
  8.         }
  9.     }
  10.     class Watermelon extends Melon {
  11.         constructor(weight, melonSort) {
  12.             super(weight, melonSort)
  13.         }
  14.         get elementIndex() {
  15.             return Number(this.weight) * Number(this.melonSort.toString().length)
  16.         }
  17.         toString() {
  18.             return `Element: Water\nSort: ${this.melonSort}\nElement Index: ${this.elementIndex} `
  19.         }
  20.     }
  21.     class Firemelon extends Melon {
  22.         constructor(weight, melonSort) {
  23.             super(weight, melonSort)
  24.         }
  25.         get elementIndex() {
  26.             return Number(this.weight) * Number(this.melonSort.toString().length)
  27.         }
  28.         toString() {
  29.             return `Element: Fire\nSort: ${this.melonSort}\nElement Index: ${this.elementIndex} `
  30.         }
  31.     }
  32.     class Earthmelon extends Melon {
  33.         constructor(weight, melonSort) {
  34.             super(weight, melonSort)
  35.         }
  36.         get elementIndex() {
  37.             return Number(this.weight) * Number(this.melonSort.toString().length)
  38.         }
  39.         toString() {
  40.             return `Element: Earth\nSort: ${this.melonSort}\nElement Index: ${this.elementIndex} `
  41.         }
  42.     }
  43.     class Airmelon extends Melon {
  44.         constructor(weight, melonSort) {
  45.             super(weight, melonSort)
  46.         }
  47.         get elementIndex() {
  48.             return Number(this.weight) * Number(this.melonSort.toString().length)
  49.         }
  50.         toString() {
  51.             return `Element: Air\nSort: ${this.melonSort}\nElement Index: ${this.elementIndex} `
  52.         }
  53.     }
  54.     class Melolemonmelon extends Melon {
  55.         constructor(weight, melonSort) {
  56.             super(weight, melonSort);
  57.             this.element = [`Water`, `Fire`, `Earth`, `Air`]
  58.         }
  59.         get elementIndex() {
  60.             return Number(this.weight) * Number(this.melonSort.toString().length)
  61.         }
  62.         morph() {
  63.             let a = this.element.shift();
  64.             this.element.push(a)
  65.         }
  66.         toString() {
  67.             return `Element: ${this.element[0]}\nSort: ${this.melonSort}\nElement Index: ${this.elementIndex} `
  68.         }
  69.     }
  70.     return {Melon, Watermelon, Firemelon, Earthmelon, Melolemonmelon}
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement