Live data from Hacker News

Laconic: A Sane Method of Generating DOM Content in JavaScript

joestelmach.github.com

31–40 of 51 posts

Re: Laconic: A Sane Method of Generating DOM Content in JavaScript

#31
post #11

Earlier quoted context omitted.

If you end up wrapping your code in an immediately called lambda anyhow I'm sure it would be fine.

Sort of, but there are some tags you probably don't want to pollute your own top-level namespace with, like a, b, i, object, p, q, and s. There's at least one tag (var) which is not allowed as an identifier on its own.

I think 'a' and 'p' are the only ones among those you'd actually want. I could probably live with with those limitations.

Re: Laconic: A Sane Method of Generating DOM Content in JavaScript

#35
post #23

This is fine for small, one-person projects, but if you generate DOM content in your JS views it will come back to bite you in the ass once you hit a certain size. The first time you need to bring in a designer, or integrate a static mockup from a designer, you'll be wishing you used a template engine. You wouldn't embed database queries into your view controllers, so why would you couple your html to your javascript…

Because database queries and views belong to different logical layers whilst JavaScript and HTML are just different technologies that may be used for things on the same logical layer.

But I think your point about designers is a valid one for many projects.

Re: Laconic: A Sane Method of Generating DOM Content in JavaScript

#36
post #10

This is pretty, but unfortunately the only performant way to generate dom elements in javascript is with HTML. HTML parsing is orders of magnitude faster in most browsers. How about a library like this to generate a string of HTML instead of dom elements?

I started one in 2009 (https://github.com/dburrows/markup-builder) inspired by Ruby's Builder library but abandoned it - it was only really useful for small amounts of code and for any sizeable project it's far better to use templates

Re: Laconic: A Sane Method of Generating DOM Content in JavaScript

#38

Earlier quoted context omitted.

Sort of, but there are some tags you probably don't want to pollute your own top-level namespace with, like a, b, i, object, p, q, and s. There's at least one tag (var) which is not allowed as an identifier on its own.

I think 'a' and 'p' are the only ones among those you'd actually want. I could probably live with with those limitations.

Now that I think about it, that might break a few sortFunction(a,b) {//do stuff with a and b} type functions of mine...

Re: Laconic: A Sane Method of Generating DOM Content in JavaScript

#39
post #11

Earlier quoted context omitted.

If you end up wrapping your code in an immediately called lambda anyhow I'm sure it would be fine.

Sort of, but there are some tags you probably don't want to pollute your own top-level namespace with, like a, b, i, object, p, q, and s. There's at least one tag (var) which is not allowed as an identifier on its own.

You could use with(){} in js so you don't have to pollute your global namespace and still have pretty code.
Post reply on HN