Question: Does JavaScript have an equivalent to PHPs output buffering (start, get_clean) or <<< EOF ... EOF syntax to wrap inline HTML in a variable? Shims, libraries, functions, anything that gets the job done in modern browsers.
Why: I’d like to try to make a MVC framework in pure JS and the thought of creating blocks of HTML using strings or reading files and doing find/replace on keywords makes me wonder how efficient/maintainable the code would be.
To answer your question, no, JavaScript doesn’t have anything like heredoc syntax. (CoffeeScript does, but ewww.)
You should take a look at how templating engines are implemented. I’m a fan of doT, which is very efficient. You define your template in a
scriptblock, load the template source from there, and the engine compiles it into a function. (One of the few legitimate uses ofeval.)This keeps your markup out of your JavaScript and in the HTML, where it belongs.