Advertisement
nikolayneykov

Untitled

Aug 13th, 2019
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class Zoo {
  2.   public static getZooInstance(): Zoo {
  3.     if (!Zoo.zooInstance) {
  4.       this.zooInstance = new Zoo();
  5.     }
  6.  
  7.     return Zoo.zooInstance;
  8.   }
  9.  
  10.   private static zooInstance;
  11.  
  12.   private _animals = [];
  13.  
  14.   private constructor() { }
  15.  
  16.   public get animals() {
  17.     return this._animals.join(' - ');
  18.   }
  19.  
  20.   public addAnimal(animal: string) {
  21.     this._animals.push(animal);
  22.   }
  23. }
  24.  
  25. const zoo1 = Zoo.getZooInstance();
  26. zoo1.addAnimal('Ivan');
  27. zoo1.addAnimal('Petko');
  28. zoo1.addAnimal('Haralampi');
  29. zoo1.addAnimal('Cenka');
  30. zoo1.addAnimal('Minka');
  31.  
  32. console.log(zoo1.animals);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement