function StringBuffer() {
this.buffer = [];
}
StringBuffer.prototype.append = function append(string) {
this.buffer.push(string);
return this;
};
StringBuffer.prototype.toString = function toString() {
return this.buffer.join("");
};
使用如下:
var buf = new StringBuffer();
buf.append("hello");
buf.append("world");
alert(buf.toString());
本文介绍了一个简单的 JavaScript StringBuffer 类实现,该类支持字符串拼接操作并提供了 toString 方法将缓冲区的内容转换为字符串。
110

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



