There are heredoc string definition methods in php and python:
php:
$sql=<<
select *
from pages
where pagename='$pn'
EOD;
python:
print """
This is an example of a string in the heredoc syntax.
This text can span multiple lines
"""
It is relatively cumbersome to splice a large number of strings in js without a heredoc-style operator:
Splicing method one:
var str = "
Here is line one
And line two
Finally, line three!
";
alert(str);
Splicing method two:
var __template =
'
'
'#salarySN# | '
'#name# | '
'#TDR_NAME# | '
'#TSD_NAME# | '
'#WORK_STATUS# | '
'#isleader_display# | '
''
'Set role'
' |
';
JS strings need to break the original string style and be processed per line, which is a bit unbearable.
Give me a solution:
function aHereDoc() {/*
Hello, World!
I am a JavaScript here document.
Use the 'hereDoc' function to extract me.
*/}
function hereDoc(func) {
return func.toString().split(/n/).slice(1, -1).join('n');
}
console.log(hereDoc(aHereDoc));
Use func.toString() to obtain the strings that need to be processed in batches, use split(/n/).slice(1, -1) to remove the first and last two lines of function definition code, and reassemble them.