Both a TreeWalker
object and a NodeIterator
object can be used to traverse a DOM tree starting from a given node. The APIs to use them, and even the APIs to create them, createTreeWalker
and createNodeIterator
look virtually identical. Both seem about equally old and neither seems to be deprecated in favour of the other.
JavaScript is hardly a stranger to duplicative, redundant APIs, but this one seems a pretty bizarre instance. Are there any meaningful differences between them, or is it just a historical accident that both exist?