
DOM Traversal in Firefox 3.5 - sant0sk1
http://hacks.mozilla.org/2009/06/dom-traversal/
======
jeresig
I posted my follow-up thoughts here: <http://ejohn.org/blog/unimpressed-by-
nodeiterator/>

~~~
niyazpk
You were criticizing the adding up of the _whatToShow_ filter parameters like:

    
    
       NodeFilter.SHOW_ELEMENT + NodeFilter.SHOW_COMMENT + NodeFilter.SHOW_TEXT
    

Can you suggest a better way than this?

~~~
jeresig
I did in my examples:

    
    
        document.getNodes( Node.ELEMENT_NODE, Node.COMMENT_NODE, Node.TEXT_NODE );
    

Although, that's still in keeping with using integers to keep track of the
results. I'd much prefer something like:

    
    
        document.getNodes( Element, Comment, Text )

~~~
niyazpk
I am probably not the best person to comment on this, but isn't this more
counter-intutive than the original addition method?

I have seen the addition stuff in many APIs like in C++ and Java.

If we start using comma separated values as you suggest, wouldn't it be more
confusing? I would defnitely confuse them for being different arguments. A
better way would be enclosing the arguments into an array (or something):

    
    
       document.getNodes("Node.ELEMENT_NODE, Node.COMMENT_NODE, Node.TEXT_NODE")
    

(I repeat, I am not the best person to comment on this. If anyone is reading
this, please take this just as a query from a student)

~~~
jeresig
"but isn't this more counter-intutive than the original addition method?"

I disagree. The original statement (using + or using |) isn't very intuitive
to most web developers. Why would you add (or concatenate?) together a text
node and a comment node? For that matter, why would you OR them together? I
think you're pretty close to noting a better approximation (e.g. passing in a
string "ELEMENT, COMMENT, TEXT") - but that would require defining a spec for
how the string should be parsed, which is also messy. It just makes a lot more
sense to just use a variable number of arguments (which JavaScript is designed
to handle gracefully).

------
niyazpk
If it were a few years ago, I would have been super excited about this. Not
that I am not now, but since I use JQuery (which by the way supports most of
these DOM traversal methods), I think this does not directly affect my code.

Of course this will significantly increase the speed of JQuery DOM traversal
if they start using these APIs for Firefox.

