Home › Forums › JavaScript › Need help with simple code › Reply To: Need help with simple code
September 14, 2013 at 2:36 pm
#150097
Participant
In that case you might as well put your original code in the IIF, it would work.
There are a lot of ways to handle this, if your IIF returns a object, you could define ‘i’ and numLog inside the function and after that return them, like so:
var css_tricks = (function () {
var i = 0;
//some code
function numLog() {
i++;
console.log(i);
return i;
}
return {
numLog: numLog
}
}())
var timerId = setTimeout(function loop(){
var i = css_tricks.numLog();
timerId = setTimeout(loop, 100)
if(i === 20) {
clearTimeout(timerId)
};
}, 100)
It pretty much depends on the effect you are trying to achieve.