代码
/**
 * @author kevin
 
*/

 
function StringBuffer(){
     
this._strings = new Array;
    
if(typeof StringBuffer.initailized == "undefined"){
        StringBuffer.prototype.append 
= function(str){
            
this._strings.push(str);
            
return this;
        }
        StringBuffer.prototype.toString 
= function(){
            
return this._strings.join('');
        }
        
        StringBuffer.initailized 
= true;
    }
 }

 
var s = new StringBuffer();
 s.append(
"my name is ").append("kevin");
 alert(s)  
//my name is kevin

 
var s2 = new StringBuffer();
 s2.append(
"my name is ").append("chengkai");
 alert(s2) 
//my name is chengkai

 

 

相关文章:

  • 2021-12-17
  • 2021-06-25
  • 2021-07-22
  • 2021-06-05
  • 2021-09-12
  • 2021-12-30
  • 2022-12-23
猜你喜欢
  • 2022-01-10
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-05-27
  • 2021-12-22
  • 2021-11-28
相关资源
相似解决方案