var StringBuilder = function(){
    
this.cache = [];
    
if(arguments.length)this.append.apply(this,arguments);
}

StringBuilder.prototype 
= {
    prepend:
function(){
        
this.cache.splice.apply(this.cache,[].concat.apply([0,0],arguments));
        
return this;
    }
,
    append:
function(){
        
this.cache = this.cache.concat.apply(this.cache,arguments);
        
return this;
    }
,
    toString:
function(){
        
return this.getString();
    }
,
    getString:
function(){
        
return this.cache.join('');    
    }

}


<script type="text/javascript" src="stringbuilder.js"></script>
<script type="text/javascript">
);
    sb.append(
'I');
    sb.append(
' am');
    sb.append(
' Robin',' Chen.');
    sb.prepend(
'hi,');
    sb.prepend(
'Hi,','hi,');
    alert(sb);
    alert(sb.getString());
javascript的StringBuilder类
</script>

相关文章:

  • 2021-12-01
  • 2022-01-14
  • 2021-04-19
  • 2021-08-25
  • 2021-06-21
  • 2022-12-23
  • 2022-12-23
  • 2022-01-20
猜你喜欢
  • 2022-03-09
  • 2021-10-14
  • 2021-11-07
  • 2022-02-27
  • 2022-12-23
  • 2021-12-14
相关资源
相似解决方案