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