原生JS實現StringBuffer

function StringBuffer(str) {
    this.__strings__ = [str];
    return this;
}

StringBuffer.prototype = {
    constructor: StringBuffer,
    append: function (str) {
        this.__strings__.push(str);
        return this;
    },
    clear: function () {
        this.__strings__ = [];
    },
    toString: function () {
        return this.__strings__.join('');

    }
};
相關文章
相關標籤/搜索