3 ms·
recreating html node declaration in JS with janky and verbose syntax for attributes and child nodes is not an answer to a problem anyone has.
by weego 6y ago
recreating html node declaration in JS with janky and verbose syntax for attributes and child nodes is not an answer to a problem anyone has.
- tobr 6y agoI guess I shouldn’t reply to flippant drive-by comments, but how the heck can that be considered verbose, and what’s your non-janky suggestion that doesn’t introduce some kind of extra tooling or parsing?
- blacktriangle 6y agoThe linked code doesn't show the full value of this technique, since its straightforward HTML that's coming out. Now what happens if you want a collection of list items generated by looping over an array? Assign classes based on some logical conditional? Conditional rendering? These are problems everybody has and every template language tries to solve with their own custom syntax. The point of this method is that rather than create some half-assed template language, you just write Javascript code that acts on and generates a data structure that can then be converted into HTML.