在JavaScript中如何在多行字符串中添加注释

3

有没有可能在JavaScript的多行字符串中添加注释?

就像这样:

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

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

谢谢


在长字符串上添加注释 - Charles
我认为除了你自己的答案之外,没有其他选择。 - Adrián
3个回答

4
我找到了一个可能性:
var string ='START - \
This is my string'+
// This should be escaped!
' - END';

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

但这并不太好...


比没有好。有时我真的想在多行字符串中添加注释以进行实验。 - Adrian Moisa

3
这种方法是不可行的。你可以这样做:
var s = "multi line" +
        //" line" +
        " string";

0

你尝试过类似这样的东西吗?

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';

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接