title: Recursion down DOM tree
body: <p>This is code from Crockford's JavaScript: The Good Parts.</p>
  
  <pre><code>var results = [];
  
  var walkDOM = function (node,func) {
          func(node);                     //What does this do?
          node = node.firstChild;
          while(node) {
              walkDOM(node,func);
              node = node.nextSibling;
          }
  
      };
  </code></pre>
  
  <p>I understand the code except for <code>func(node)</code>. I guess the point is to pass <code>node</code> as a parameter in function <code>func</code>, but how will the browser understand it this way? <code>node</code> and <code>func</code> could be anything--so when the function is called it could read like this:</p>
  
  <pre><code>walkDOM(document.body,function(att) {
            node.getAttribute(att);
            results.push(node);
            });
  </code></pre>
  
  <p>When <code>func</code> is passed, <code>walkDOM</code> will process function(att) {...}(document.body)--which wouldn't make any sense. So why has Crockford chosen to include func(node)? </p>