Copy codeThe Code is as follows:
<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<Html xmlns = "http://www.w3.org/1999/xhtml">
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8"/>
<Title> </title>
</Head>
<Body>
</Body>
<Script type = "text/javascript"> <! --
Var str = 'hello ';
Str + = 'World ';
// Steps 2 to 6 are performed each time the string connection is completed.
// In fact, the steps behind the scenes are as follows:
/**//*
1. Create a string for storing 'hello'
2. Create a string for storing 'World'
3. Create a string that stores the link result
4. Copy the current content of str to the result.
5. Copy 'World' to the result.
6. Update str to point it to the result
*/
// To improve the performance, it is best to concatenate strings using arrays.
// 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 concatenate strings
// Step 2 is performed each time string connection is completed
// In fact, the steps behind the scenes are as follows:
/**//*
1. Create a string for storing results
2. copy each string to a proper position in the result.
*/
Var buffer = new StringBuffer ();
Buffer. append ('hello ');
Buffer. append ('World ');
Var result = buffer. toString ();
// Use StringBuffer for analogy + = save 50% ~ 66% of the time
// -->
</Script>
</Html>