>From: David McDivitt <x12code-del@del-yahoo.com>[color=blue]
>Subject: Re: setting tab index
>Date: Fri, 08 Apr 2005 08:15:20 -0500
>[color=green]
>>Subject: Re: setting tab index
>>Date: Fri, 8 Apr 2005 01:46:43 +0100
>>
>>David McDivitt wrote:[color=darkred]
>>>>From: David McDivitt <x12code-del@del-yahoo.com>[/color]
>><snip>[color=darkred]
>>>> function setTabs (childObject) {
>>>> for (j=0;j<childObject.childNodes.length;j++) {
>>>> try {
>>>> childObject.childNodes[j].tabIndex = tab;
>>>> tab++;
>>>> if
>>>>(childObject.childNodes[j].childnodes.length > 0)
>>>>setTabs(childObject.childNodes[j]); //should not have to
>>>>check length before recurse[/color]
>><snip>[color=darkred]
>>> When observing values it seemed stuff was not being
>>> saved on the stack when recursion was done.[/color]
>><snip>
>>
>>"Saved on the stack"? You are using a global variable - j - as a loop
>>counter in a recursive function. Global variables are not contained by
>>(restricted to) an execution context so they cannot be expected to be
>>"saved on the stack" (in so far as javascript's stack of execution
>>contexts can be regarded as a stack).
>>
>>Don't waste time, and clock cycles, implementing your own stack, just
>>follow the general programming axiom that variables should never be
>>given more scope than they absolutely need and use local variables.
>>Learning to do so habitually will save you a lot of time and trouble in
>>the long run.
>>
>>Richard.[/color]
>
>The variable j is used only within the setTabs function and is not mentioned
>outside that function. How does it therefore have a global scope? Everything
>having local scope within the function should go on the stack. That's the
>way other languages work. I read articles saying javascript does not put
>stuff on the stack very well when doing recursion, so your criticism is not
>well founded.[/color]
Reading Microsoft documentation at
http://msdn.microsoft.com/library/de...sproglobal.asp
it says if the var statement is not used, the variable defaults to global
scope. Your criticism may be correct, Richard. I will try using var instead.
Thanks