Javascript heredoc

后端 未结 14 1614
盖世英雄少女心
盖世英雄少女心 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:24

    How about this:

    function MyHereDoc(){
    /*HERE
    

    This is written in the HEREDOC, notice the multilines :D.

    HERE

    And Here

    HERE*/ var here = "HERE"; var reobj = new RegExp("/\\*"+here+"\\n[\\s\\S]*?\\n"+here+"\\*/", "m"); str = reobj.exec(MyHereDoc).toString(); str = str.replace(new RegExp("/\\*"+here+"\\n",'m'),'').toString(); return str.replace(new RegExp("\\n"+here+"\\*/",'m'),'').toString(); } //Usage document.write(MyHereDoc());

    Just replace "/*HERE" and "HERE*/" with word of choice.

提交回复
热议问题