5 ms·
For the people saying "just use jQuery always, is not that much of a perfomance hit", is just blatantly false; any complex manipulation and you start seeing the
by ivanca 13y ago
For the people saying "just use jQuery always, is not that much of a perfomance hit", is just blatantly false; any complex manipulation and you start seeing the difference right away; many times I have to use both, native selectors for performance but mixed with jQuery (for efficiency).
Also, there are many scenarios where you can safely use things like querySelectorAll like browser extensions, WebGL apps, 2D canvas apps, (native) WebCam apps, WebRTC apps and many more. Furthermore, at this point is arguable how useful is to support IE8 and below.
And this article falls very short of what can be achieved with the native implementation. For example thanks to JS being prototypical you can borrow almost any method from Array to your NodeList.
[].filter.call(document.getElementsByTagName('a'), function(e){
return e.innerText === 'Brackets';
});
- laughinghan 13y agoTechnically not because JS is prototypical, but because of how ES5 defines `Array.prototype.filter`.
- ivanca 13y ago> Prototype-based programming is a style of object-oriented programming in which classes are not present, and behavior reuse (from Wikipedia)
- kibibu 13y ago> Furthermore, at this point is arguable how useful is to support IE8 and below I'm seeing this a lot, but IE8 is the highest "blue e that goes on the internet" on Windows XP. Its a brave (consumer-facing) business that can dump 10% of its customers [1] [1] http://gs.statcounter.com/#browser_version-ww-monthly-201305-201305-bar http://gs.statcounter.com/#browser_version-ww-monthly-201305...
- ivanca 13y agoIf you ask them to use another browser some of them will; so I argue is less than 10%. As a side-note "document.querySelectorAll" is supported by IE8, but unfortunately it doesn't have Array.prototype.filter nor other basic array methods.
- jarek-foksa 13y ago[].filter.call() creates unnecessary Array instance, you should be using Array.prototype.filter.call() instead. Still, such code breaks encapsulation and is plain ugly. It would make much more sense if document.getElementsByTagName() was returning Array instance or if NodeList was inheriting from Array.