var list = querySelectorAll(selector);
var i;
for (i = 0; i < list.length; i++)
list[i].value = value;
Is just as readable as: $(selector).val(value);
Except that the jQuery example requires you to be familiar with jQuery. The first, however, just requires you to be familiar with a for loop, which is a common construct in many languages. Being faster is just a happy by-product.I, personally, am starting to use Dart instead, because it is a nice middleground between jQuery and raw DOM manipulation; it doesn't hide the details like jQuery does and it's still fast.
Ihe best argument I can see is with XMLHttpRequest, which is still a pain because it doesn't have a nice API.
* animations: CSS3
* templating: I don't do it, I prefer static pages and toggle sections with classes
* element filtering: better selectors (nth-child, nth-of-type, [data-stuff=''], etc)
* form serialization: either use event handlers and build it as you go or just use regular browser form handling
Currently, I use reqwest [1] for my HTTP requests. It's very small and is cross browser. In Dart, I just use the built-in libraries.
queryAll(selector).forEach((e) => e.value = value);
To me this is quite readable, and it's really nothing special about Dart, it's just that the dart:html library uses real Dart collections rather than the very unfortunate DOM NodeList.To go even further into jQuery territory, there are bugs requesting that queryAll() return an ElementList that has setters that effect every element in the list, so we could do this:
queryAll(selector).value = value;
I'm on the fence about that. It's short, but a little magical. I'm sure jQuery fans would like to have it though. document.querySelectorAll(selector).forEach(function (elem) { value = somevalue; });
Which is more obvious in intent and more flexible.Except this doesn't work, because that's not a real array, it's a stupid NodeList. :(
So you'd have to do:
Array.prototype.slice.call(document.querySelectorAll('thing'), 0).forEach(function (elem) { value = somevalue; });
ugh. Array.prototype.forEach.call(document.querySelectorAll('thing'), function (elem) { value = somevalue; }); _.each(document.querySelectorAll('thing'), function (elem) { value = somevalue; });
(But then I might as well just use jQuery, I guess)Can you tell me what does this line of code without checking what the f value is?
$(f);
Every time I have to look at plain ol' javascript it feels like my eyes are going to bleed. Regardless of whether I wrote it myself or whether another developer wrote it.
On the other hand, jQuery (still not the Miss World of programming languages..) is far easier on the eyes.
Also, for most apps, the performance impact isn't all that noticeable since most of the performance hit happens due to reflows and not because of jQuery. Plus, the Google CDN jQuery is pretty well cached in most browsers.