js 高效拼接字符串
<script>
//如果我们大量使用+=进行字符串拼接的话,将会使界面失去响应(卡死状态) //高效拼接字符串 var StringBuilder=function() { this.data=[]; } StringBuilder.prototype.append=function(){ this.data[this.data.length]=arguments[0]; //比push方法高效 return this; } StringBuilder.prototype.clear=function(){ this.data=[]; this.data.length=0; } StringBuilder.prototype.toString=function(){ if(arguments.length > 0){ return this.data.join(arguments[0]); } else{ return this.data.join(''); } } var mystr=new StringBuilder(); mystr.append("abc").append("def").append('123'); alert(mystr.toString()); </script>