JSFiddle - React, Tailwind, and code Playground
by lasha
JavaScript
var timerContainer = {};
for (var i = 1; i <= 2; i++) {
var currentStep = 0;
timerContainer[i] = function(param1, param2) {
console.log("param1: ", param1);
console.log("param2: ", param2);
var theInterval;
var timer = {};
timer.set = function() {
theInterval = setInterval(function() {
console.log("timeout called" + currentStep);
currentStep++;
}, 4000);
console.log("SET interval", theInterval);
}
timer.stop = function() {
console.log("cleared", theInterval);
window.clearInterval(theInterval);
}
return timer;
}
}
// Automatically triggering actions since there's no GUI
var thefreakingtimeout;
setTimeout(function(){
console.log("timerContainer triggered!");
thefreakingtimeout = timerContainer[1]("first","second");
thefreakingtimeout.set();
},2000)
setTimeout(function(){
console.log("timerContainer stopped!");
thefreakingtimeout.stop();
},15000)