Advertisement
Lulunga

Classes 03. Unity rats

Oct 18th, 2019
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class Rat {
  2.     constructor(name){
  3.         this.name = name;
  4.         this.unitedRats = [];
  5.     }
  6.     unite(otherRat) {
  7.         if (otherRat instanceof Rat){
  8.             this.unitedRats.push(otherRat);
  9.         }
  10.     }
  11.     getRats() {
  12.         return this.unitedRats;
  13.     }
  14.     toString() {
  15.         return `${this.name}\n${this.unitedRats.map(r=>`##${r}`).join('')}`
  16.     }
  17. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement