Copy Code code as follows:
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 "/>
<title></title>
<body>
</body>
<script type= "Text/javascript" ><!--
var str = ' Hello ';
str = ' world ';
Steps 2 through 6 are performed each time a string connection is completed
In fact, the steps that this code performs behind the scenes are as follows:
/**//*
1. Create a string that stores ' hello '
2. Create a string that stores ' world '
3. Create a string that stores the results of a link
4. Copy the current contents of STR to the results
5. Copy ' World ' to results
6. Update Str so that it points to the result
*/
The best way to improve performance is to use array methods to stitch strings
Create a StringBuffer class
function StringBuffer () {
this.__strings__ = [];
};
StringBuffer.prototype.append = function (str) {
This.__strings__.push (str);
};
StringBuffer.prototype.toString = function () {
Return This.__strings__.join (");
};
Call the StringBuffer class to implement the concatenation string
Perform step 2 each time you complete a string connection
In fact, the steps that this code performs behind the scenes are as follows:
/**//*
1. Create a string that stores the results
2. Copy each string to the appropriate location in the result
*/
var buffer = new StringBuffer ();
Buffer.append (' Hello ');
Buffer.append (' World ');
var result = buffer.tostring ();
Use + + to save 50%~66% time with StringBuffer analogy
-->
</script>