Javascript heredoc

后端 未结 14 1585
盖世英雄少女心
盖世英雄少女心 2020-12-02 12:55

I need something like heredoc in JavaScript. Do you have any ideas for this? I need cross-browser functionality.

I found this:

heredoc = \'\\
14条回答
  •  抹茶落季
    2020-12-02 13:08

    As others have said, ES6 template strings give you most of what traditional heredocs provide.

    If you want to go a step further and use a tagged template string, theredoc is a nice utility function that lets you do this:

    if (yourCodeIsIndented) {
      console.log(theredoc`
        Theredoc will strip the
        same amount of indentation
        from each line.
    
          You can still indent
          further if you want.
    
        It will also chop off the
        whitespace-only first and
        last lines.
      `)
    }
    

提交回复
热议问题