Unimpressed by NodeIterator. John Resig, one of the most talented API designers I’ve ever come across, posts some well earned criticism of the document.createNodeIterator DOM traversal API.
Unimpressed by NodeIterator. John Resig, one of the most talented API designers I’ve ever come across, posts some well earned criticism of the document.createNodeIterator DOM traversal API.
Starting a meta discussion over here cos the comments there are too busy...
While an improvement, I'm not that keen on his propsed alternative. I've personally always found bitwise arguments a bit odd, but I'm not sure they're necessarily un-javascripty.
I wouldn't say passing in variable arguments is a particularly clean design, or inherently javascripty either. It only works in this case because he's eliminated all other arguments. I've never felt that comfortable using
argumentsor PHP'sfunc_get_args(), they often lead to pretty inflexible and magical function signatures that trip you up down the road with unforeseen usage patterns.Maybe what's needed is a sensible default, with the option to change the behaviour in subsequent config methods. Something like:
By using a constructor, this is a bit closer to the original
createNodeIteratorbut I don't see it as particularly non-javascripty.What is "Javascripty" anyway? I'd say it's more a set of conventions that have arisen based on the design of libraries like Prototype and jQuery, and developers familiar with each will give you different answers to that question. Javascript's flexible enough to support loads of different stylistic quirks.
That said, and after writing this, iterators do seem like strange beasts to me too. So maybe John's proposal isn't too bad, although I'd include
document.getElements()too, and keep on the bitwise arguments for the more complicated case. They make sense once you grok them.There's a lot in Javascript that most developers don't fully understand at first, closures, scoping rules, arrays (!). I'd say bitwise operations are pretty basic in comparison.
James Wheare - 20th June 2009 11:35 - #