[whatwg] Fake Code

On Wed, Jul 30, 2008 at 2:42 AM, Ian Hickson <ian at hixie.ch> wrote:
> On Tue, 29 Jul 2008, Garrett Smith wrote:
>>

>   var s = "";
>   test(document,
>       function (a) { s += "enter " + a + "\n"; },
>       function (a) { s += "exit " + a + "\n"; });
>   s
>
> The output was what I expected. There were no syntax errors. Could you
> elaborate on what else you think is wrong other than the "do"?
>

Ah, makes more sense now. The extra 'do' threw me off (I was also
tired when I first looked at it). It would need an identifier to avoid
confusing the parser, though (either that or assign it in an
assignment statement). It looks like you're calling the function
'test'.

--------------------------------------------------------
function walkTree(root, enter, exit) {
 var node = root;
 start: while (node) {
   enter(node);
   if (node.firstChild) {
     node = node.firstChild;
     continue start;
   }
   while (node) {
     exit(node);
     if (node.nextSibling) {
       node = node.nextSibling;
       continue start;
     }
     if (node == root)
       node = null;
     else
       node = node.parentNode;
   }
 }
}

Garrett
--------------------------------------------------------
> --
> Ian Hickson               U+1047E                )\._.,--....,'``.    fL
> http://ln.hixie.ch/       U+263A                /,   _.. \   _\  ;`._ ,.
> Things that are impossible just take longer.   `._.-(,_..'--(,_..'`-.;.'
>

Received on Wednesday, 30 July 2008 19:03:47 UTC