This is code from Crockford\'s JavaScript: The Good Parts.
var results = [];
var walkDOM = function (node,func) {
func(node); //
Crockford's code is passing a callback to walkDOM which can be used in many ways to process the arguments passed to it.
An example could be a method which returns the count of all DOM elements with the specified tagName:
var getTagNameCount = function(tagName) {
var count = 0;
walkDOM(document.body, function(node) {
if (node.tagName === tagName) {
count++;
}
});
return count;
};