Comment by varenc
2 days ago
TIL that
js_func`string`
is valid JS and calls `js_func` as a tagged template literal, passing it a TemplateStringsArray. Going to use "console.log`weeee`" in my code now.
2 days ago
TIL that
js_func`string`
is valid JS and calls `js_func` as a tagged template literal, passing it a TemplateStringsArray. Going to use "console.log`weeee`" in my code now.
It's not common but few libraries use that to support JSX-like syntax at runtime, without a build step.
e.g. https://github.com/developit/htm and https://lit.dev/docs/components/rendering/
I recently used the feature in a code embedded image generator so I could have compact images store tiny images in inline code.
https://gisthost.github.io/?8d537c4a3b2331e7c6c45d31f1900330
The Trashcan in that sampler is stored as
decoded to a SVG D path by
which can be turned into an image by
The Sampler contains all of the images in the html file and still comes out to be only 13k. Probably quite a bit less if you removed the ray tracer and scenes.
🗑 is prettier :)
Niiice! I finally understand the origin of this JS syntax used in SQL queries and GraphQL:
sql`SELECT * FROM users WHERE id = ${userId}`
const q = gql` query GetUser { user(id: ${userId}) { name email } } `;
They're called "tagged template literals". Here's the docs:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...