Javascript heredoc

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

    Depending on what flavour of JS/JS engine you're running (SpiderMonkey, AS3) you can simply write inline XML, into which you can place text on multiple lines, like heredoc:

    var xml = 
        Here 
        is 
        some 
        multiline 
        text!
    
    
    console.log(xml.toXMLString())
    console.log(xml.toString()) // just gets the content
    

提交回复
热议问题