09-11
24

用js实现StringBuffer连接字符串

function StringBuffer(){//自定义一个StringBuffer类。以便提高String的连接字符串性能
this._strings = new Array;
}
StringBuffer.prototype.append = function(str){
this._strings.push(str);
}
StringBuffer.prototype.toString = function(){
return this._strings.join("");//join()用参数里面的字符串连接Array里面的值
}

function test(){
var strb = new StringBuffer();
strb.append("hello");
strb.append("world");
alert(strb.toString());
}


文章来自: 本站原创
引用通告: 查看所有引用 | 我要引用此文章
Tags: StringBuffer
相关日志:
评论: 0 | 引用: 0 | 查看次数: 369
发表评论
昵 称:
密 码: 游客发言不需要密码.
内 容:
验证码: 验证码
选 项:
虽然发表评论不用注册,但是为了保护您的发言权,建议您注册帐号.
字数限制 1000 字 | UBB代码 开启 | [img]标签 关闭