//为了提高性能最好使用数组方法拼接字符串
//创建一个StringBuffer类
function StringBuffer(){
this.__strings__ = [];
};
StringBuffer.prototype.append = function(str){
this.__strings__.push(str);
};
StringBuffer.prototype.toString = function(){
return this.__strings__.join('');
};
//调用StringBuffer类,实现拼接字符串
//每次完成字符串连接都会执行步骤2步
//实际上,这段代码在幕后执行的步骤如下:
/**//*
1.创建存储结果的字符串
2.把每个字符串复制到结果中的合适位置
*/
var buffer = new StringBuffer();
buffer.append('hello ');
buffer.append('world');
var result = buffer.toString();
//用StringBuffer类比使用+=节省50%~66%的时间
//-->
script>