You can have multiline strings in pure JavaScript.

This method is based on the serialization of functions, which is defined to be implementation-dependent. It does work in the most browsers (see below), but there's no guarantee that it will still work in the future, so do not rely on it.

Using the following function:

function hereDoc(f) { return f.toString(). replace(/^[^\/]+\/\*!?/, ''). replace(/\*\/[^\/]+$/, ''); }

You can have here-documents like this:

var tennysonQuote = hereDoc(function() {/*! Theirs not to make reply, Theirs not to reason why, Theirs but to do and die */});

The method has successfully been tested in the following browsers (not mentioned = not tested):

IE 4 - 10

Opera 9.50 - 12 (not in 9-)

Safari 4 - 6 (not in 3-)

Chrome 1 - 45

Firefox 17 - 21 (not in 16-)

Rekonq 0.7.0 - 0.8.0

Not supported in Konqueror 4.7.4

Be careful with your minifier, though. It tends to remove comments. For the YUI compressor, a comment starting with /*! (like the one I used) will be preserved.

I think a real solution would be to use CoffeeScript.

ES6 UPDATE: You could use backtick instead of creating a function with a comment and running toString on the comment. The regex would need to be updated to only strip spaces. You could also have a string prototype method for doing this:

let foo = ` bar loves cake baz loves beer beer loves people `.removeIndentation()

Someone should write this .removeIndentation string method... ;)