Wrap long template literal line to multiline without creating a new line in the string

后端 未结 9 1420
谎友^
谎友^ 2020-12-01 02:40

In es6 template literals, how can one wrap a long template literal to multiline without creating a new line in the string?

For example, if you do this:



        
9条回答
  •  青春惊慌失措
    2020-12-01 02:56

    This is an old one. But it came up. If you leave any spaces in the editor it will put them in there.

    if
      const text = `a very long string that just continues\
      and continues and continues`;
    

    just do the normal + symbol

    if
      const text = `a very long string that just continues` +
      `and continues and continues`;
    

提交回复
热议问题