自己封装一个js的StringBuffer类

function StringBuffer(str)
{
    var arr = [];
    str = str || "";
    arr.push(str);
    this.append = function(str1)
    {
        arr.push(str1);
        return this;
    };
    this.toString = function()
    {
        return arr.join("");
    };
};

document.onreadystatechange = function(){
    if(document.readyState == "complete")    
    {
        var sb = new StringBuffer();
        sb.append("Hello,").append("World");
        alert(sb.toString());
    }
};


你可能感兴趣的:(自己封装一个js的StringBuffer类)