by lhorie · 13y ago · 0 comments
1 - is there no equivalent for .closest()? Traversal from relative paths is kind of a big deal for a jQuery-like tool
2 - what is the type of `HTML.body.div`? HTMLDivElement or Array? If it depends on your markup, then that's a recipe for easy breakage
1 - you cannot be sure that return types will not change in the future (e.g. markup changes in maintenance phase), especially in large projects with lots of devs, hence my comment about brittleness.
2 - each() is verbose and encourages procedural style, which can cause redraw performance hits (i.e. someElements.readDOM().writeDOM() redraws much faster than someElements.each(function(el) {el.readDOM().writeDOM()}) since the browser's engine doesn't need to recalculate layout at every iteration
re: closest() - I've seen people do things like
$("li ul").closest("li").addClass("has-children")
for things like dynamic expandable tree initialization. Granted, it's not a very common use case though.2) elements.each('readDom').each('writeDom', 'value')
3) HTML.find('li ul').each('parentNode.classList.add', 'has-children')