Javascript版的StringBuffer

/**定义StringBuffer字符串对象类**/

function StringBuffer() {
    this._strings = new Array();
}

StringBuffer.prototype.append = function(str) {
    this._strings.push(str);
    return this;
};
StringBuffer.prototype.toString = function() {
    var str = arguments.length == 0 ? """" : arguments[0];
    return this._strings.join(str);
};
StringBuffer.prototype.clear = function() { // 清空数组
    this._strings.length = 0;
};

你可能感兴趣的:(js,StringBuffer)