SHARE
TWEET

ES6ClassesBasic

avr39-ripe Apr 7th, 2020 203 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function Ticker(tickerId, baseDelay=3000, ticksCount=10)
  2. {
  3.     //let this = {};
  4.     console.log("Ticker works hard with new! :)");
  5.     this.tickerId = tickerId;
  6.     this.delay = baseDelay;
  7.     this.ticksCount = ticksCount;
  8.     this.cnt = 0;
  9.     this.id;
  10.     Ticker.prototype.parentProperty = 42;
  11.     Ticker.prototype.tickerArr = () => {
  12.             console.log(`Ticker #${this.tickerId} ${this.cnt}`);
  13.             (this.cnt++) % 2 ? this.delay *= 2 : this.delay /= 2;
  14.             if (this.cnt == this.ticksCount && this.ticksCount != -1) { clearTimeout(this.id); }
  15.             else { this.id = setTimeout(this.tickerArr, this.delay)};
  16.     };
  17.     Ticker.prototype.armArr = function()
  18.     {
  19.         this.cnt = 0;
  20.         this.id = setTimeout(this.tickerArr, this.delay);
  21.     }
  22.     Ticker.prototype.arm = function()
  23.     {
  24.         this.cnt = 0;
  25.         this.id = setTimeout(function ticker(obj){
  26.             console.log(`Ticker #${obj.tickerId} ${obj.cnt}`);
  27.             (obj.cnt++) % 2 ? obj.delay *= 2 : obj.delay /= 2;
  28.             if (obj.cnt == obj.ticksCount && obj.ticksCount != -1) { clearTimeout(obj.id); }
  29.             else { obj.id = setTimeout(ticker, obj.delay,obj)};
  30.         },this.delay,this);
  31.     };
  32.     Ticker.prototype.disarm = function()
  33.     {
  34.         clearTimeout(this.id);
  35.     };
  36.     Ticker.prototype.set = function(baseDelay=3000, ticksCount=10)
  37.     {
  38.         this.delay = baseDelay;
  39.         this.ticksCount = ticksCount;
  40.     };
  41.    
  42.     Ticker.prototype.get = function()
  43.     {
  44.         console.log(`Ticker #${this.tickerId}\nDelay: ${this.delay}\nTicksCount: ${this.ticksCount}`);
  45.     }
  46.     //Object.setPrototypeOf(this,Ticker.prototype)
  47.     //return this;
  48. };
  49.  
  50. class User
  51. {
  52.     constructor(fName, sName)
  53.     {
  54.         // let this = {};
  55.         this.fName = fName;
  56.         this.sName = sName;
  57.     };
  58.     userRanks = [];
  59.  
  60.     printFullName()
  61.     {
  62.         console.log(`${this.fullName}`);
  63.     };
  64.  
  65.     getRanks() { return this.userRanks;};
  66.  
  67.     get fullName() { return `${this.fName} ${this.sName}`;};
  68. }
  69.  
  70.  
  71. class Admin extends User
  72. {
  73.     constructor(defaultServer, ...args)
  74.     {
  75.         super(...args);
  76.         this.defaultServer = defaultServer;
  77.     };
  78.  
  79.     getDefaultServer() { return this.defaultServer; };
  80.     setDefaultServer(defaultServer) { this.defaultServer = defaultServer; };
  81. }
  82.  
  83. class Ticker
  84. {
  85.     constructor(tickerId, baseDelay=3000, ticksCount=10)
  86.     {
  87.         this.tickerId = tickerId;
  88.         this.delay = baseDelay;
  89.         this.ticksCount = ticksCount;
  90.     };
  91.    
  92.     cnt = 0;
  93.     id = 0;
  94.  
  95.     ticker()
  96.     {
  97.         console.log(`Ticker #${this.tickerId} ${this.cnt}`);
  98.         (this.cnt++) % 2 ? this.delay *= 2 : this.delay /= 2;
  99.         if (this.cnt == this.ticksCount && this.ticksCount != -1) { clearTimeout(this.id); }
  100.         else { this.id = setTimeout(()=>{this.ticker()}, this.delay)};
  101.     };
  102.  
  103.     arm()
  104.     {
  105.         this.cnt = 0;
  106.         this.id = setTimeout(()=>{this.ticker()},this.delay);
  107.     };
  108.  
  109.     disarm()
  110.     {
  111.         clearTimeout(this.id);
  112.     };
  113.  
  114.     set(baseDelay=3000, ticksCount=10)
  115.     {
  116.         this.delay = baseDelay;
  117.         this.ticksCount = ticksCount;
  118.     };
  119.    
  120.     get()
  121.     {
  122.         console.log(`Ticker #${this.tickerId}\nDelay: ${this.delay}\nTicksCount: ${this.ticksCount}`);
  123.     };
  124. }
  125.  
  126. class CssClass {
  127.     constructor(name)
  128.     {
  129.         this.name = name;
  130.         this.arrForStyles = [];
  131.     }
  132.  
  133.    
  134.    
  135.     addStyles()
  136.     {
  137.         for (let i = 0; i < arguments.length; i++)
  138.         {
  139.             this.arrForStyles.push(arguments[i]);
  140.         }
  141.         return this.arrForStyles;
  142.     }
  143.  
  144.     delStyle(deleteStyle)
  145.     {
  146.         let indexOfDel = this.arrForStyles.indexOf(deleteStyle, 0);
  147.         this.arrForStyles.splice(indexOfDel, 1);
  148.         return this.arrForStyles;
  149.     }
  150.  
  151.     getCss()
  152.     {
  153.         console.group(`${this.name}`)
  154.         console.log(`${this.arrForStyles.join(' ')}`)
  155.         console.groupEnd()
  156.     }
  157.    
  158. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top