Small number of good, many words on a dense pile of text, exquisite artistic youth, will use a large number of character join symbols even with indentation, forced into several lines. For example:
Copy Code code as follows:
var html =
' <div> ' +
' <p>Hello</p> ' +
' <p>world ' </p> ' +
' </div> ';
That's fine, if there's a lot of double quotes in the string, it's even more troublesome, and the various escape characters look dazzling.
In fact, there is a small little skill, it can solve the problem. People always think that strings must be in "..." or ' ... ', that's right. But there is also a place where the string can also be preserved as code semantics, which is the ToString of a function, which outputs the entire code of the functions as a string-the annotation part of which is reserved!
So we write an empty function with a/**/annotation, which is the constant content we want. After the ToString plus a regular will be able to extract what we want!
Try it now:
Copy Code code as follows:
var res_code = _text (function () {/*
#include <iostream>
int main ()
{
Std::cout << "Hello World" << Std::endl;
return 0;
}
*/});
var res_poem = _text (function () {/*
More blowing, stars like rain.
BMW Carving Car Incense full road.
Feng Xiao Sound move, the jade pot light turn, one night fish dragon dance.
The Moth is the golden wisp of snow Willow,
The laughter of the incense went.
The crowd searched him for 1100 degrees,
Suddenly looking back, the man is in the dim lights.
*/});
var res_xml = _text (function () {/*
<projectDescription>
<name>Hello</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>com.adobe.flexbuilder.project.flexbuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>com.adobe.flexbuilder.project.apollobuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
</projectDescription>
*/});
function _text (Wrap) {
Return wrap.tostring (). Match (/\/\*\s ([\s\s]*) \s\*\//) [1];
}
alert (Res_code);
alert (RES_POEM);
alert (res_xml);
Ok! is the chrome in the comments in front of each line tab removed, if just put the code is not a big problem ~ Of course, there is a prerequisite is the word character can not appear * *
It is important to note that when compressing the code, the annotation is filtered, and part of the manual exclusion is required.