Multiline strings that don't break indentation

前端 未结 5 1400
离开以前
离开以前 2020-12-30 18:32

According to this esdiscuss discussion, it is possible in ECMAScript 6 to define multiline strings without having to place subsequent lines of the string at the very beginni

5条回答
  •  無奈伤痛
    2020-12-30 19:04

    You can also just do a string replace for double spaces (assuming your indentation uses spaces, not tabs). Obviously any double spaces in your actual string would be removed, but for most cases this should be ok.

    const MSG = (`Line 1
              line 2
              line 3`).replace(/  +/g, '');
    // outputs
    /*
    Line 1
    line 2
    line 3
    */
    

提交回复
热议问题