代码
/**
 * @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

 

 

 posted on 2009-12-06 20:06  将军  阅读(519)  评论(0编辑  收藏  举报