maymunskoa

UnitedRats - Objects and Classess/more exercises/

Jul 15th, 2020
98
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.     getRats(){
  7.         return this.unitedRats;
  8.     }
  9.     unite(object){
  10.         if(object instanceof Rat){
  11.             this.unitedRats.push(object);
  12.         }
  13.         return;
  14.     }
  15.  
  16.     toString(){
  17.         let output = `${this.name}\n`;
  18.         for (const object of this.unitedRats) {
  19.            
  20.             output += `##${object.name}\n`;
  21.         }
  22.         return output;
  23.     }
  24. }
Advertisement
Add Comment
Please, Sign In to add comment