javascript下高性能字符串连接StringBuffer类

 更新时间:2010年08月16日 23:38:14   作者:  
使用StringBuffer类比使用加号节省50%左右的时间,大家对于大数据的连接最好使用这个方法。
复制代码 代码如下:

function StringBuffer(){
this.__strings__ = new Array();
}
StringBuffer.prototype.append = function(str){
this.__strings__.push(str);
};
StringBuffer.prototype.toString = function(){
this.__strings__.join(" ");
};

其实上面的代码,主要利用了js的数组原理实现。

相关文章

最新评论