function StringBuilder() { this._stringArray = new Array(); } StringBuilder.prototype.append = function(str) { this._stringArray.push(str); } StringBuilder.prototype.toString = function(joinGap) { return this._stringArray.join(joinGap); } function TestArray() { var stringBuilder = new StringBuilder(); stringBuilder.append("good"); stringBuilder.append("moring"); var str= stringBuilder.toString(" "); alert(str); }
详细:
https://www.cnblogs.com/matthew/archive/2008/08/15/1268843.html