W3C home > Mailing lists > Public > whatwg@whatwg.org > July 2008

[whatwg] Fake Code

From: Garrett Smith <dhtmlkitchen@gmail.com>
Date: Wed, 30 Jul 2008 19:03:47 -0700
Message-ID: <c9e12660807301903g5eb088f6vb6c094b4b522d584@mail.gmail.com>
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

This archive was generated by hypermail 2.4.0 : Wednesday, 22 January 2020 16:59:04 UTC