4 ms·
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
by jeresig 17y ago
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 17y agoI 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 17y ago"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).