There are heredoc ways to define strings in PHP and Python:
Php:
The code is as follows |
Copy Code |
$sql =<<<eod SELECT * From pages where Pagename= ' $PN ' EOD; |
Python:
The code is as follows |
Copy Code |
Print "" " This is a example of a string in the Heredoc syntax. This text can span multiple lines """ |
JS concatenation of a large number of strings no heredoc style operators are more cumbersome:
Splicing Way One:
The code is as follows |
Copy Code |
var str = " Here's line one and line two Finally, Line three! ";
alert (str); |
Splicing mode two:
The code is as follows |
Copy Code |
var __template = ' <tr> ' + ' <td> #salarySN #</td> ' + ' <td> #name #</td> ' + ' <td> #TDR_NAME #</td> ' + ' <td> #TSD_NAME #</td> ' + ' <td> #WORK_STATUS #</td> ' + ' <td> #isleader_display #</td> ' + ' <td> ' + ' <a href= ' javascript:void ( -1) ' > Set role </a> ' + ' </td></tr> '; |
JS strings need to break the original string style, each row processing, this is a bit unbearable.
Give a solution:
The code is as follows |
Copy Code |
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)); |
uses func.tostring () to get the string that needs to be processed in batches, using split (/n/). Slice (1,-1) to remove the code defined by the two lines of function, and reassemble it.
refer:http://trentrichardson.com/2010/11/11/javascript-heredoc-like-syntax/