2013-01-10 87 views
2

是否有可能在JavaScript多行字符串中添加註釋?JavaScript中多行字符串的註釋

事情是這樣的:

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

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

感謝

+0

你爲什麼要那樣做? –

+0

添加對長字符串的評論 – Charles

+0

我不認爲除了你自己的答案之外還有其他選擇。 –

回答

2

這是不可能的。你可以這樣做:

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

我發現了一種可能性:

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

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

但它不是那麼好看...

+0

總比沒有好。有時候我真的想用多行字符串來評論一些東西來進行實驗。 –

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