• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

Chapter 9. Recursive Approach > Recursion in Practice

Recursion in Practice

First we streamline the shownode function. (This function is independent of the recursion but part of tightening up the code.) The function is renamed trace(). The flabby generic node printer is replaced by specialized single-line traces for element, text node, and attribute.

But the real action happens after the node data is printed on the screen. Trace scans through the array of child nodes and installs itself in each as the .trace() method—which it immediately invokes. (Alternatively, we could have added trace() to XML.prototype.)


PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


  
  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint