function FinderBuilder(newDocument) {
// private
    var doc = newDocument;

    function buildIdFinder(e) {
        if (e.id) {
            var id = e.id;

            return (function(targetDoc) {
                return targetDoc.getElementById(id);
            });
        }

        return null;
    }

    function buildTagNameFinder(e) {
        var elements = doc.getElementsByTagName(e.tagName);

        for (var i = 0, n = elements.length; i < n; ++i) {
            if (elements[i] === e) {
                // both the descendant axis and getElementsByTagName() should
                // return elements in document order; hence the following index
                // operation is possible
                return (function(targetDoc) {
                    return targetDoc.getElementsByTagName(e.tagName)[i];
                });
            }
        }

        return null;
    }

// public
    this.setDocument = function(newDocument) {
        doc = newDocument;
        return this;
    };

    this.build = function(e) {
        return (
            buildIdFinder(e) ||
            buildTagNameFinder(e)
        );
    };
}
function FinderBuilder(newDocument) {
// private
    var doc = newDocument;

    function buildIdFinder(e) {
        if (e.id) {
            var id = e.id;

            return (function(targetDoc) {
                return targetDoc.getElementById(id);
            });
        }

        return null;
    }

    function buildTagNameFinder(e) {
        var elements = doc.getElementsByTagName(e.tagName);

        for (var i = 0, n = elements.length; i < n; ++i) {
            if (elements[i] === e) {
                // both the descendant axis and getElementsByTagName() should
                // return elements in document order; hence the following index
                // operation is possible
                return (function(targetDoc) {
                    return targetDoc.getElementsByTagName(e.tagName)[i];
                });
            }
        }

        return null;
    }

// public
    this.setDocument = function(newDocument) {
        doc = newDocument;
        return this;
    };

    this.build = function(e) {
        return (
            buildIdFinder(e) ||
            buildTagNameFinder(e)
        );
    };
}
function FinderBuilder ( newDocument ) { // private var doc = newDocument ; function buildIdFinder ( e ) { if ( e . id ) { var id = e . id ; return ( function ( targetDoc ) { return targetDoc . getElementById ( id ) ; } ) ; } return null ; } function buildTagNameFinder ( e ) { var elements = doc . getElementsByTagName ( e . tagName ) ; for ( var i = 0 , n = elements . length ; i < n ; ++ i ) { if ( elements [ i ] === e ) { // both the descendant axis and getElementsByTagName() should // return elements in document order; hence the following index // operation is possible return ( function ( targetDoc ) { return targetDoc . getElementsByTagName ( e . tagName ) [ i ] ; } ) ; } } return null ; } // public this . setDocument = function ( newDocument ) { doc = newDocument ; return this ; } ; this . build = function ( e ) { return ( buildIdFinder ( e ) || buildTagNameFinder ( e ) ) ; } ; }
///////////////////////////////////////////////////////////////////////////// 
Builds and returns closures that take a document and return a node.
///////////////////////////////////////////////////////////////////////////// Builds and returns closures that take a document and return a node .
Constructor for FinderBuilder