News for hackers. Stuff that matters.
Re:TinyJS – Shorten JavaScript QuerySelect with $ and $$ by dpweb on Wednesday October 02, 2024 @04:09PM (#41724551)
If ya don't want to do includes,

` window.$ = document.querySelector.bind(document) window.$$ = document.querySelectorAll.bind(document) `

Re:TinyJS – Shorten JavaScript QuerySelect with $ and $$ by qingcharles on Wednesday October 02, 2024 @04:47PM (#41724825)
Thanks, this is the more useful bit of the code to me.

edit: how about this so you can use array functions too when you need?

window.$ = document.querySelector.bind(document);

window.$$ = document.querySelectorAll.bind(document);

window.$$$ = (selector) => Array.from(document.querySelectorAll(selector));

Re:TinyJS – Shorten JavaScript QuerySelect with $ and $$ by janalsncm on Wednesday October 02, 2024 @05:58PM (#41725347)
I’ve been doing this for years. Lightweight but still saves me a ton of time.