Advertisement
AreWe

Unity

Jul 6th, 2020
899
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function Rat(name) {
  2.     this.name = name;
  3.     this.unitedRats = [];
  4.  
  5.     Object.defineProperties(this, {
  6.         unite: {
  7.             value: (rat) => {
  8.                 if (!(rat instanceof Rat)) {
  9.                     return;
  10.                 }
  11.  
  12.                 this.unitedRats.push(rat);
  13.             },
  14.             enumerable: false,
  15.         },
  16.         getRats: {
  17.             value: () => this.unitedRats,
  18.             enumerable: false,
  19.         },
  20.         toString: {
  21.             value: () => `${this.name}${this.unitedRats.map((r) => `\n##${r.name}`).join('')}`,
  22.             enumerable: false,
  23.         },
  24.     });
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement