News for hackers. Stuff that matters.
Re:Cash: An absurdly small jQuery alternative for modern bro... by nedt on Sunday November 03, 2024 @06:40AM (#42032496)
querySelectorAll() isn't live. So you could do what I very often do and already convert the result to an array, i.e.

  dqsA = s => Array.from(document.querySelectorAll(s));
Reason why I do that very often is because it allows all array methods to be used on the result, like .map() or .filter(), which makes it feel very much like jQuery. YMMV
Re:Cash: An absurdly small jQuery alternative for modern bro... by theandrewbailey on Sunday November 03, 2024 @07:54AM (#42032783)

    NodeList.prototype.__proto__ = Array.prototype;
Problem solved without Array.from().
Re:Cash: An absurdly small jQuery alternative for modern bro... by cr125rider on Sunday November 03, 2024 @08:16AM (#42032898)
Does the underlying data structure work okay with that? I would assume there is some sort of lazy iterator involved that may not work with array methods, or only work once.

This is JavaScript though…

Re:Cash: An absurdly small jQuery alternative for modern bro... by jazzypants on Sunday November 03, 2024 @09:36AM (#42033285)
Prototype pollution is bad. We learned this over a decade ago.
Re:Cash: An absurdly small jQuery alternative for modern bro... by mg on Sunday November 03, 2024 @09:51AM (#42033366)
Good point!

I wonder what I would have to look for in my codebase in terms of what could break when dqsA starts returning an array instead of a NodeList?

Re:Cash: An absurdly small jQuery alternative for modern bro... by WorldMaker on Monday November 04, 2024 @02:35PM (#42045245)
The versions of those methods (map/filter/reduce/etc) that support any iterator (including upgrading NodeList "for free") have passed Stage 4 of the process, which means they will be in the next version of the standard and already starting to show up in some browsers.

https://github.com/tc39/proposal-iterator-helpers