TinyJS – Shorten JavaScript QuerySelect with $ and $$
1–10 of 94 posts
Re: TinyJS – Shorten JavaScript QuerySelect with $ and $$
#2Like jQuery but for 2024?
Re: TinyJS – Shorten JavaScript QuerySelect with $ and $$
#3> This README was generated by ChatGPT
Damn good README. Also, good library.
Re: TinyJS – Shorten JavaScript QuerySelect with $ and $$
#4Like jQuery but for 2024?
I dig it
Re: TinyJS – Shorten JavaScript QuerySelect with $ and $$
#5I do believe I've seen something like this under another name.
Using "$" to shorten JavaScript? That seems a lot like jQuery.
> This README was generated by ChatGPT
You don't need AI to explain this one.
Re: TinyJS – Shorten JavaScript QuerySelect with $ and $$
#6This is the whole code:
(() => {
const assignDeep = (elm, props) => Object.entries(props).forEach(([key, value]) =>
typeof value === 'object' ? assignDeep(elm[key], value) : Object.assign(elm, {[key]: value}))
const tagNames = ['a', 'abbr', 'address', 'area', 'article', 'aside', 'audio', 'b', 'base', 'bdi', 'bdo', 'blockquote', 'body', 'br', 'button', 'canvas', 'caption', 'cite', 'code', 'col', 'colgroup', 'data', 'datalist', 'dd', 'del', 'details', 'dfn', 'dialog', 'div', 'dl', 'dt', 'em', 'embed', 'fieldset', 'figcaption', 'figure', 'footer', 'form', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'head', 'header', 'hr', 'html', 'i', 'iframe', 'img', 'input', 'ins', 'kbd', 'label', 'legend', 'li', 'link', 'main', 'map', 'mark', 'meta', 'meter', 'nav', 'noscript', 'object', 'ol', 'optgroup', 'option', 'output', 'p', 'param', 'picture', 'pre', 'progress', 'q', 'rp', 'rt', 'ruby', 's', 'samp', 'script', 'section', 'select', 'small', 'source', 'span', 'strong', 'style', 'sub', 'summary', 'sup', 'table', 'tbody', 'td', 'template', 'textarea', 'tfoot', 'th', 'thead', 'time', 'title', 'tr', 'track', 'u', 'ul', 'var', 'video', 'wbr' ].forEach(tag => window[tag] = function(...args) {
const props = typeof args[0] == 'object' && !(args[0] instanceof HTMLElement) ? args.shift() : null
const elm = document.createElement(tag)
props && assignDeep(elm, props)
elm.append(...args.map(a => typeof a == 'string' ? document.createTextNode(a) : a))
return elm
})
window['$'] = selector => document.querySelector(selector)
window['$$'] = selector => Array.from(document.querySelectorAll(selector))
})()Re: TinyJS – Shorten JavaScript QuerySelect with $ and $$
#7may 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)
Re: TinyJS – Shorten JavaScript QuerySelect with $ and $$
#8[flagged]
Re: TinyJS – Shorten JavaScript QuerySelect with $ and $$
#9jQuery 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
Re: TinyJS – Shorten JavaScript QuerySelect with $ and $$
#10[flagged]
[deleted]