function StringBuffer(){
this._strings = new Array();
}
StringBuffer.prototype.append = function(str){
this._strings.push(str);
}
StringBuffer.prototype.toString = function(){
return this._strings.join("");
}
//使用
var buffer = new StringBuffer();
buffer.append("Hello");
buffer.append(" World!");
alert(buffer.toString());
javascript模拟StringBuffer类
最新推荐文章于 2023-04-28 12:16:52 发布
本文介绍了一种自定义StringBuffer类的方法,该类能够通过append方法添加字符串,并通过toString方法将所有添加过的字符串连接起来返回。示例代码展示了如何创建此类并使用它来拼接字符串。
853

被折叠的 条评论
为什么被折叠?



