by ahoge · 14y ago · 0 comments
Yep, it's ancient. Chrome and Firefox are on average about 3 weeks old. IE8 is over 50 times older.
>jQuery's main raison d'être might have gone out the window.
Normalization was just one part. It still provides a much nicer API. There are also events, AJAX, effects, and some useful helpers.
[].slice.call(document.querySelectorAll('p')).forEach(function (el) {console.log(el);});
vs $('p').each(function () {console.log(this);});I hope you realize that by saving yourself a few characters you've sacrificed an unknown amount of performance from your site. For such a simple query I'd use getElementsByTagName instead.
The point was to demonstrate that the API is somewhat flawed since it doesn't return something usable. The "clever" short version was used to show that you have to write quite a bit more code - even if you make it really ugly.
>For such a simple query I'd use getElementsByTagName instead.
It's a generic example. The selector was kept short and simple for the sake of brevity.
But is that really the best possible use of your time?
BTW that could be written like this:-
[].forEach.call(document.querySelectorAll('p'), function (el) { console.log(el); });