3 ms·
>[IE8] was released in 2009! 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
by ahoge 14y ago
>[IE8] was released in 2009!
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);});
- MatthewPhillips 14y agoAgreed, [].slice.call is show-offy and pointless. Array.prototype.slice.call is the way to go. 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.
- ahoge 14y ago>Array.prototype.slice.call is the way to go. 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.
- salmanapk 14y agoGood point. BTW that could be written like this:- [].forEach.call(document.querySelectorAll('p'), function (el) { console.log(el); });
- apendleton 14y agoArray.prototype.forEach didn't arrive in IE until 9, so if the point is that you can do anything that jquery can do, this won't work.
- salmanapk 14y agohuh? Might want to check the comment I was replying to.
- leaverou 14y agoUm, when did we forget how to write our own abstractions? It’s not black and white, either jQuery or vanilla JS with no helpers.
- ahoge 14y agoYes, we can of course reinvent our own untested and undocumented triangular wheels. But is that really the best possible use of your time?