Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function Ticker(tickerId, baseDelay=3000, ticksCount=10)
- {
- //let this = {};
- console.log("Ticker works hard with new! :)");
- this.tickerId = tickerId;
- this.delay = baseDelay;
- this.ticksCount = ticksCount;
- this.cnt = 0;
- this.id;
- Ticker.prototype.parentProperty = 42;
- Ticker.prototype.tickerArr = () => {
- console.log(`Ticker #${this.tickerId} ${this.cnt}`);
- (this.cnt++) % 2 ? this.delay *= 2 : this.delay /= 2;
- if (this.cnt == this.ticksCount && this.ticksCount != -1) { clearTimeout(this.id); }
- else { this.id = setTimeout(this.tickerArr, this.delay)};
- };
- Ticker.prototype.armArr = function()
- {
- this.cnt = 0;
- this.id = setTimeout(this.tickerArr, this.delay);
- }
- Ticker.prototype.arm = function()
- {
- this.cnt = 0;
- this.id = setTimeout(function ticker(obj){
- console.log(`Ticker #${obj.tickerId} ${obj.cnt}`);
- (obj.cnt++) % 2 ? obj.delay *= 2 : obj.delay /= 2;
- if (obj.cnt == obj.ticksCount && obj.ticksCount != -1) { clearTimeout(obj.id); }
- else { obj.id = setTimeout(ticker, obj.delay,obj)};
- },this.delay,this);
- };
- Ticker.prototype.disarm = function()
- {
- clearTimeout(this.id);
- };
- Ticker.prototype.set = function(baseDelay=3000, ticksCount=10)
- {
- this.delay = baseDelay;
- this.ticksCount = ticksCount;
- };
- Ticker.prototype.get = function()
- {
- console.log(`Ticker #${this.tickerId}\nDelay: ${this.delay}\nTicksCount: ${this.ticksCount}`);
- }
- //Object.setPrototypeOf(this,Ticker.prototype)
- //return this;
- };
- class Ticker
- {
- constructor(tickerId, baseDelay=3000, ticksCount=10)
- {
- this.tickerId = tickerId;
- this.delay = baseDelay;
- this.ticksCount = ticksCount;
- this.cnt = 0;
- this.id = 0;
- Ticker.prototype.tickerArr = () => {
- console.log(`Ticker #${this.tickerId} ${this.cnt}`);
- (this.cnt++) % 2 ? this.delay *= 2 : this.delay /= 2;
- if (this.cnt == this.ticksCount && this.ticksCount != -1) { clearTimeout(this.id); }
- else { this.id = setTimeout(this.tickerArr, this.delay)};
- };
- }
- armArr()
- {
- this.cnt = 0;
- this.id = setTimeout(this.tickerArr, this.delay);
- }
- arm()
- {
- this.cnt = 0;
- this.id = setTimeout(function ticker(obj){
- console.log(`Ticker #${obj.tickerId} ${obj.cnt}`);
- (obj.cnt++) % 2 ? obj.delay *= 2 : obj.delay /= 2;
- if (obj.cnt == obj.ticksCount && obj.ticksCount != -1) { clearTimeout(obj.id); }
- else { obj.id = setTimeout(ticker, obj.delay,obj)};
- },this.delay,this);
- };
- disarm()
- {
- clearTimeout(this.id);
- };
- set(baseDelay=3000, ticksCount=10)
- {
- this.delay = baseDelay;
- this.ticksCount = ticksCount;
- };
- get()
- {
- console.log(`Ticker #${this.tickerId}\nDelay: ${this.delay}\nTicksCount: ${this.ticksCount}`);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement