TreeWalker constructor
TreeWalker instances can only be created with Document.prototype.createTreeWalker. Is this by necessity, due to some relationship created between a given Document and TreeWalker up front, or is this just historical? I didn’t see anything obvious in the spec that suggested TreeWalkers maintain a relationship to the Document from which they were created — it doesn’t even appear the Node argument has to have the same ownerDocument.
Asking mainly because it would be lovely to be able to just write new TreeWalker.
As with NodeIterator this is the historical design, probably with Java to blame. I haven't tried to constructors added as I expected developers to not use these classes. If that expectation is wrong and there's implementation interest, then constructors could definitely be added.
I expected developers to not use these classes.
Perhaps it’s less common than I thought. I’ve used it fairly often over the years — being able to skip subtrees with the filter can be pretty useful — but it’s true that there are lots of alternatives. Any particular reasons you’d expect it not to be used much anymore?
In general I think it would be less surprising if foo.createBar ops that produce instances of Bar but don’t actually make use of foo all had ordinary constructor ops on Bar, but I’d agree TreeWalker probably isn’t a high priority item.
If I remember correctly NodeIterator and TreeWalker were only implemented in a cross-browser fashion following Acid3. And that was probably the wrong decision and we should have tried to get them removed instead as by then lots of other ways were added to traverse the DOM as well.