So, I am seeing a curious problem. If I have a function
// counter wraps around to beginning eventually, omitted for clarity.
var counter;
cycleCharts(chartId) {
// chartId should be undefined when called from setInterval
console.log('chartId: ' + chartId);
if(typeof chartId == 'undefined' || chartId < 0) {
next = counter++;
}
else {
next = chartId;
}
// ... do stuff to display the next chart
}
This function can be called explicitly by user action, in which case chartId
is passed in as an argument, and the selected chart is shown; or it can be in autoplay mode, in which case it's called by a setInterval
which is initialized by the following:
var cycleId = setInterval(cycleCharts, 10000);
The odd thing is, I'm actually seeing the cycleCharts()
get a chartId
argument even when it's called from setInterval
! The setInterval
doesn't even have any parameters to pass along to the cycleCharts
function, so I'm very baffled as to why chartId
is not undefined when cycleCharts
is called from the setInterval
.