JSFiddle - React, Tailwind, and code Playground
JavaScript
var c = new Countdown();
c.seconds = 10;
c.start();
function Countdown()
{
this.appId = null;
this.timerId = null;
this.seconds = null;
this.decrementCounter = function (instant)
{
if (instant == null)
return;
instant.tick();
console.log(instant.seconds);
if (instant.seconds === 0)
{
instant.tickEnd();
instant.stop();
}
instant.seconds--;
};
this.tick = function ()
{
var xx = this.appId
};
this.tickEnd = function ()
{
var xx = this.appId
};
this.start = function ()
{
clearInterval(this.timerId);
this.timerId = setInterval((function(scope) {return function() {scope.decrementCounter(scope);};})(this), 1000);
};
this.stop = function ()
{
clearInterval(this.timerId);
};
}