【问题标题】:Comment in multiline string in JavaScriptJavaScript 中的多行字符串注释
【发布时间】:2013-01-10 12:22:04
【问题描述】:

是否可以在 javascript 多行字符串中添加注释?

类似这样的:

var string = 'START - \
This is part of my string\
\\ This should be escaped!\
-END ';

// string = 'START - This is part of my string - END';

谢谢

【问题讨论】:

  • 对长字符串添加注释
  • 我认为除了您自己的答案之外没有其他选择。

标签: javascript string comments multiline


【解决方案1】:

我发现了一种可能性:

var string ='START - \
This is my string'+
// This should be escaped!
' - END';

// string = 'START - This is my string - END'

但它不是那么好......

【讨论】:

  • 总比没有好。有时我真的很想在多行字符串中注释某些内容以进行试验。
【解决方案2】:

这是不可能的。你可以这样做:

var s = "multi line" +
        //" line" +
        " string";

【讨论】:

    【解决方案3】:

    你尝试过这样的事情吗?

    var string = 'This is part of your string';
    string += 'This is second part of your string'; //Comment yout want to add
    string += 'This is thirdpart of your string';
    

    【讨论】:

      猜你喜欢
      • 2014-01-20
      • 2011-02-04
      • 1970-01-01
      • 1970-01-01
      • 2010-09-07
      • 1970-01-01
      • 2016-08-31
      • 2019-06-10
      • 1970-01-01
      相关资源
      最近更新 更多