How do you code wrap-around line endings in JavaScript?

I have a series of lines like this in my JavaScript file (very old code):

function chart1() {
document.getElementById('chart1').innerHTML = '<br><style>#chart1but\{display:none;\}</style>'
+ 'more stuff here'

However, Sublime Text cautions, “Misleading line break before ‘+’; readers may interpret this as an expression boundary.”

Is there a more proper way to do this? It works as is.

It’s an attempt at ES6 Template literals.

more stuff here
even a ${variable} or ${variable2.also}`

Warning: Template Literals are ES6, and as such are not currently supported by certain browsers (coughIEasusualcough)

Code linters like JSLint prefer the plus symbol to be at the end of the line, with the rest of the text being indented - not just by 4 spaces, but by 8 for clarity.

function chart1() {
    document.getElementById('chart1').innerHTML = "<br>" +
            "<style>#chart1but\{display:none;\}</style>" +
            "more stuff here";

“how do I code wrap-around line endings?”

(off-topic, it’s me, but innerHTML grates a bit) anyway,

let some_str = "a bunch of stuff"; 
  some_str += "more stuff"; 
  some_str += "even more stuff"; 
  some_str += "etc. etc. until done"; 

Typing some_str over and over would drive me nuts.

If I absolutely had to do it over a long set of strings…and support IE…sigh…

let output = [ "I'm a string,",
"I'm another string",
"And another"]
output.push("Hey this is the middle of a code block.");
return output.join("\r\n")

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.