Perhaps an odd question but here it goes: I have a function which I call periodically and within that function I need to know which iteration I\'m in, or how many times the
You'll have to use a closure. Normally you would use a static variable. in Javascript it would look something like:
jQuery( document ).ready( function(){
setInterval( myFunction, 3000 );
});
var myFunction = (function(){
var count = 0;
return function(){
count++
alert( "I have been called " + count + " times");
}
})();
Demonstration: http://jsfiddle.net/MZQ83/2/