Re:TinyJS – Shorten JavaScript QuerySelect with $ and $$
by 123yawaworht456 on Wednesday October 02, 2024 @03:36PM
(#41724291)
may I ask what's the point of `const tagNames =`? removing it would make no difference, as far as I can tell - just make sure the previous line ends with a semicolon (or add it at the same line as the opening square bracket)
[ Parent
| on HN ]
Re:TinyJS – Shorten JavaScript QuerySelect with $ and $$
by hoten on Wednesday October 02, 2024 @03:58PM
(#41724470)
Well, it's polluting the global window scope with all those helpers.
That's a reason to never use this imo.
There are plenty of other jquery-lite helper libraries out there. 95 percent the utility with hardly any cost in terms of script size.
Converting querySelectorAll to an array is honestly most of the benefit of these libraries.
Re:TinyJS – Shorten JavaScript QuerySelect with $ and $$
by spankalee on Wednesday October 02, 2024 @04:13PM
(#41724574)
> Converting querySelectorAll to an array is honestly most of the benefit of these libraries.
Now that NodeList is iterable, I don't even know that converting to an array is that useful anymore.
[...document.querySelector('div')] is pretty easy.
Iterator.from(document.querySelector('div')) too (doesn't work yet in Safari).
Re:TinyJS – Shorten JavaScript QuerySelect with $ and $$
by xPaw on Wednesday October 02, 2024 @04:15PM
(#41724596)
You don't need to convert querySelectorAll to an array, you can directly iterate it, or use forEach.
Re:TinyJS – Shorten JavaScript QuerySelect with $ and $$
by meow_catrix on Wednesday October 02, 2024 @04:23PM
(#41724666)
Not if you want to map or reduce it.
Re:TinyJS – Shorten JavaScript QuerySelect with $ and $$
by smusamashah on Wednesday October 02, 2024 @04:04PM
(#41724515)
Yes, exactly. The first two statements have no use in the last two lines that this library is for. Or may be I don't understand Javascript much.