HTML
HTML copied to clipboard
proxy dot-traversal into first element
Im learning DOM from the code, I dont understand why you offer the first element instead of traverse it. eg: I have two ul elements.
<ul><li>1</li><li>2</li></ul>
<ul><li>3</li><li>4</li></ul>
now HTML.body.ul.li only get the first ul's li, its very odd. and the second ul dont inherit any methods, i must use HTML.ify to initial it by manully.
How about write like this:
if (force || !list.each) {
if (!list.slice){ list = _.slice.call(list); }
_.methods(list);
for (var i = 0, len = list.length; i < len; i++) {
_.node(list[i], force);
}
}
Yeah, i figured someone would complain about this someday. The trouble is with non-uniform structures in the same list. Your list has all ul that contain lis in it, so HTML.body.ul.li makes all the sense in the world. But what about HTML.query('.foo') where there are multiple .foo elements that all are different tags and have different child tags? It gets messy, and could even become a performance drag for large lists with many/diverse child elements.
Basically, i tried to keep it simple here. I knew that cases like HTML.body.ul.li could always be worked around: HTML.body.ul.query('li'), but that if i proxied all child elements from all list members that people working with large/diverse lists could get confusing/slow proxied getters even if they were not using them.
I could probably be swayed on this, but for now, i thinking avoiding a potential problem that couldn't be worked around easily is better than creating a surprising behavior that can be worked around easily.
Oh, and let's leave this open for others to comment. I'm very interested in hearing from the community on this one.
Thanks for explain.