Skip to content Skip to sidebar Skip to footer

Unable To Make Recursive Call In Javascript

When I try to run this program, I get an error in Firefox saying that: moveDate is undefined on line 41 (referring to the line window.setTimeout('moveDate()',100);. Any ideas w

Solution 1:

Yes, they are. Yet, window.setTimeout("moveDate()",100); will eval that code string in the global scope - no moveDate to be found there. Instead, pass the function reference to setTimout():

window.setTimeout(moveDate, 100);

Solution 2:

"moveDate" is scoped inside of the monthScroller method. Anything outside of the brackets of the monthScroller function can't see the "moveDate" function. So... when the setTimeout runs, the scope "window" and window doesn't have a function named "moveDate" in scope. What you need to do is change the call to the following:

setTimeout(moveDate,100);

That should work for you. That way you are passing the moveDate function/object into the setTimeout.

Post a Comment for "Unable To Make Recursive Call In Javascript"