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)
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.
TinyJS – Shorten JavaScript QuerySelect with $ and $$
31–40 of 94 posts
Re: TinyJS – Shorten JavaScript QuerySelect with $ and $$
#32jQuery II: The Quickening! I recently built a toy Golang SSR project using Zepto, a jQuery-like library, and felt like I was 17 again (**EDIT: it's unmaintained - don't use it). Also of note is that "Highlander II" takes place in the year 2024 [1]. It's a sign! Everything old is new again! `$` is immortal! [1] https://en.wikipedia.org/wiki/Highlander_II:_The_Quickening
Zepto is unmaintained, which isn’t good for security issues or bugs, unfortunately. jQuery proper is both maintained and has actively been working on a 4.0 release and still gets security and bug fixes
Re: TinyJS – Shorten JavaScript QuerySelect with $ and $$
#33Why would this make any sense? const myDiv = div( {id: 'container', className: 'my-class'}, h1('Hello World'), p('This is a dynamically generated paragraph.') ); document.body.appendChild(myDiv); That's completely unnecessary these days with template strings. It's gonna be much faster as well to use browser's native parsing. const div = document.createElement('div'); let text = 'This is a dynamically generated paragr…
Re: TinyJS – Shorten JavaScript QuerySelect with $ and $$
#34Why would this make any sense? const myDiv = div( {id: 'container', className: 'my-class'}, h1('Hello World'), p('This is a dynamically generated paragraph.') ); document.body.appendChild(myDiv); That's completely unnecessary these days with template strings. It's gonna be much faster as well to use browser's native parsing. const div = document.createElement('div'); let text = 'This is a dynamically generated paragr…
Re: TinyJS – Shorten JavaScript QuerySelect with $ and $$
#35Why would this make any sense? const myDiv = div( {id: 'container', className: 'my-class'}, h1('Hello World'), p('This is a dynamically generated paragraph.') ); document.body.appendChild(myDiv); That's completely unnecessary these days with template strings. It's gonna be much faster as well to use browser's native parsing. const div = document.createElement('div'); let text = 'This is a dynamically generated paragr…
One big difference and why I've been experimenting with JSX[1] is that in that example, if the `text` comes from an untrusted source it can lead to XSS, which TinyJS prevents (I checked)! [1] https://x.com/FPresencia/status/1838176000267452704
Re: TinyJS – Shorten JavaScript QuerySelect with $ and $$
#36Earlier quoted context omitted.
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.
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 $$
#37Earlier quoted context omitted.
window['$'] = selector => document.querySelector(selector) window['$$'] = selector => Array.from(document.querySelectorAll(selector)) is really what I want to have
I'm quite fond of a little helper like so: createElement({ className: 'p-2 flex justify-end', contents: createElement({ tag: 'img', src: '/os-logo-maps.svg' }), }); I got the idea from Lea Verou's blissfuljs. When you're creating a bunch of nested elements it comes in handy.
Re: TinyJS – Shorten JavaScript QuerySelect with $ and $$
#38Why would this make any sense? const myDiv = div( {id: 'container', className: 'my-class'}, h1('Hello World'), p('This is a dynamically generated paragraph.') ); document.body.appendChild(myDiv); That's completely unnecessary these days with template strings. It's gonna be much faster as well to use browser's native parsing. const div = document.createElement('div'); let text = 'This is a dynamically generated paragr…
Re: TinyJS – Shorten JavaScript QuerySelect with $ and $$
#39jQuery II: The Quickening! I recently built a toy Golang SSR project using Zepto, a jQuery-like library, and felt like I was 17 again (**EDIT: it's unmaintained - don't use it). Also of note is that "Highlander II" takes place in the year 2024 [1]. It's a sign! Everything old is new again! `$` is immortal! [1] https://en.wikipedia.org/wiki/Highlander_II:_The_Quickening
"There can be only one"
Re: TinyJS – Shorten JavaScript QuerySelect with $ and $$
#40Why would this make any sense? const myDiv = div( {id: 'container', className: 'my-class'}, h1('Hello World'), p('This is a dynamically generated paragraph.') ); document.body.appendChild(myDiv); That's completely unnecessary these days with template strings. It's gonna be much faster as well to use browser's native parsing. const div = document.createElement('div'); let text = 'This is a dynamically generated paragr…