The original --Javascript you beat all functions!!!

Recommended for you: Get network issues from WhatsUp Gold. Not end users.

JavaScript isn't like Python can be more convenient for writing a string, such as Python can write this string:

mStr="""
   line1
   line2
   'line3'
"""

While JavaScript can only use + and assembled

mStr="line1"+
      "line2"+
      "'line3'";

The habit of this usage of the python, together with JavaScript special. Last night after work back to the room of meditation, suddenly have a brain wave, ah! The original JavaScript can also easily make multiple line. The principle is to construct a function, within the function

Write notes, such as

fun=function(){
    /*
         line1
         line2
         line3
   */
}

And then put the fun into a string, simply and an empty string can be added:

funStr=fun+"";

You might have a string such as the following

"function(){
    /*
         line1
         line2
         line3
   */
}"

Then write a function to extract the string notes content. Without treatment '"escape.

The complete code and sample please see below:

<html>
<head>
    <meta http-equiv="content-type" content="text/html;charset=gbk">
    <script>
        function $string(fun){
            var funStr=fun+"";
            var reg=/\/\*/img;
            var r=reg.exec(funStr);
            var start=null;
            var stop=null;
            if(r){
                start=reg.lastIndex;
                reg=/\*\//img;
                r=reg.exec(funStr);
                if(r){
                    stop=reg.lastIndex;
                    return funStr.substring(start,stop-2);
                }
            }
            throw "Syntax error..."
        }
        var myString=$string(
            function(){ 
                /*
                    <table>
                        <tr>
                            <td>The user name </td> <td> password</td>
                        </tr>
                        <tr>
                            <td style="widht:20px;">@name</td><td>zf123456</td>
                        </tr>
                    </table>
                */
            }
        );
        alert(myString);
    </script>
</head>
<body>

</body>
</html>


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download

Posted by Jessica at November 16, 2013 - 9:03 PM