Advertisement
avr39ripe

jsSingeltoneDraft

Jun 7th, 2021
879
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <script>
  2.         'use strict'
  3.         {
  4.  
  5.             let BaseInstance;
  6.  
  7.             class Base {
  8.                 constructor(id) {
  9.                     // this = new Object();
  10.                     // this = {};
  11.                     this._id = id;
  12.  
  13.                     if (!BaseInstance) {
  14.                         BaseInstance = this;
  15.                     }
  16.                     return BaseInstance;
  17.                 }
  18.                 getId() { return this._id };
  19.                 print() { console.log(`Hello, from Base class with id: ${this._id}`); };
  20.             }
  21.         }
  22.  
  23.         {
  24.             let bc1 = new Base(1);
  25.             let bc2 = new Base(2);
  26.             let bc3 = new Base(3);
  27.  
  28.             bc1.print();
  29.             bc2.print();
  30.             bc3.print();
  31.  
  32.             console.log(`Are objects differ? : ${bc1 != bc2}`);
  33.             console.log(`Are objects differ? : ${bc2 != bc3}`);
  34.         }
  35.     </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement