by XLcommerce · 14y ago · 0 comments
Then have a jQuery-like API when it's useful or improves clarity.
And if you "enjoy" jQuery, you have no frame of reference. It's far more inconsistent than the DOM implementations and the documentation is terrible.
What quirks is jquery saving you from dealing with? There are some, but I'd like the reader to actually think about this for a moment.
Many simply defer to jquery now and have lost curiosity about the underlying browsers (which have been rapidly improving).
Oh and try querying for something like this in ie6.
'.class + .other_class > .yet_another_class'
Having css3 query support in legacy browsers is awesome.
Not to mention productivity gains from method chaining and batch assignment such as
$('.somehting').find('*').css({'font-weight': 'bold'});
Do you really want to type the 10-20 lines of JS that are required to make that happen? I don't.
"event normalization" is another "nice-to-have" that isn't necessary. DOM 0 event handlers (e.g. `node.onclick`) have worked for decades. Each node may only be allowed one handler, but there's more than enough nodes to get the job done. Of course, event delegation can be used to handle more than one event, so this becomes moot.
I can guarantee you that the frivolous "productivity" gains from chaining Frankenstein queries like yours are mitigated by massive speed losses from parsing.
Those 'Frankenstein' queries are ridiculously easy to read and to type.
'massive speed losses from parsing'
Nobody is searching the entire dom for matching nodes.
The single biggest performance killer... far more important than tree traversal is event overhead. As long as you think long and hard before applying a new event handler (and use delegation whenever possible) you'll be fine even with those 'Frankenstein' queries hehe :P
The DOM is not CSS.
What does that even mean in this context?? How does it further your point?
illustrates a continued ignorance of the DOM
enlighten us then...
Smart aleck doesn't suit you.
Obviously, you can use standard DOM methods (e.g. gEBTN, gEBCN) with the "closest node" as well.
And, assuming you mean an element node, you just bought yourself a world of hurt. jQuery and the like will use the Selectors API (e.g. QSA) when it suits them, and due to their disagreement with the specs, element nodes don't suit them. Some scripted query engines (e.g. YUI) ignore the disagreement, favoring wrong answers fast over right ones slower.
When the libraries use their own query code, performance and compatibility go right down the toilet.
In other words, use QSA with the document node, unless you want to relearn how queries work.
> Having css3 query support in legacy browsers is awesome.
Except that you don't have anything close to that (assuming you are using one of the "popular" libraries). And, even if you did, would you really want to send that crap to an iPhone?
Only way to do it efficiently is to load the library inside conditional comments and use QSA for everything else. That is assuming you can find a query engine that actually works as expected in IE 6/7.
>> massive speed losses from parsing > Nobody is searching the entire dom for matching nodes.
Parsing selectors is parsing selectors, regardless of how they will be used. One element or the entire DOM; it doesn't make a bit of difference.
> The single biggest performance killer... far more important than tree traversal is event overhead. As long as you think long and hard before applying a new event handler (and use delegation whenever possible) you'll be fine even with those 'Frankenstein' queries hehe :P
Again, event delegation is unrelated to queries. It's silly to assume you can use wasteful queries with impunity as long as you don't attach too many listeners.
Oh, but wait, jQuery tangles up queries and event delegation with its "Live" feature. So you are screwed either way. :(
And those "Frankenstein queries" are the exact opposite of self-documenting code (something most jQuery proponents/marketers get backwards).
There are still some differences in modern browsers but those can mostly be repaired with polyfills.
Oh, and while I would not recommend doing your chaining operation (chaining just makes it harder to debug), I can write the same thing in one line of JavaScript:
Array.prototype.slice.call(document.querySelectorAll('.something > *')).forEach(function(el) { el.className += ' bold-font'; });Why not just use a extremely well tested library that automatically gives you full browser support? All for the equivalent price of one very small jpeg file.
Absolutely NOT. The results vary per jQuery version as they have been struggling to grasp the subtle differences for six years.
No it isn't as you send all of the supporting junk code to the newer browsers that don't need it.
> Not to mention productivity gains from method chaining and batch assignment such as $('.somehting').find('*').css({'font-weight': 'bold'});
Chaining has nothing to do with queries.
> Do you really want to type the 10-20 lines of JS that are required to make that happen? I don't.
Then learn to write (cross-browser) functions that fit your needs. Leave the ham-fisted queries alone.
I used to do a lot of work in Flash, and one of the nicest parts was knowing that what you write works as intended across environments. One of the nice side-effects of the HTML5 mob is that the browser vendors are putting a lot of work into both improving their APIs and doing so in a cross-compatible way.
We've gotten to such a point of jQuery saturation that it seems some of us have forgotten why we use it in the first place. Which is really just the other side of the coin of people blindly using it without knowing why.
I lead a team of developers building web apps day in and day out. I have a number of fairly cutting edge web samples in the wild. A "trust me" on an anonymous board is completely meaningless to me.
As grandparent says, dealing with these quirks is a waste of time and effort.
There are far less quirks than many imagine them to be. Further by providing some trivial syntactical sugar, jquery encourages a development style that is orthogonal with the DOM, incurring a significant performance penalty (horrid abuses like Twitter).
I'm not saying not to use jquery, and we do in several of our projects. But we justify why we use it, and never perversely demand a justification why not.