1 /**
  2  * 新しいStringBufferオブジェクトを作成する。
  3  * @class 文字列をバッファリングし、文字列の効率的な結合を行うクラス
  4  * @param {String} [str] バッファリングする文字列
  5  * @example alert(new StringBuffer("このように").append("文字列を").append("結合します。").toString());
  6  */
  7 function StringBuffer(str) {
  8 	/**
  9 	 * バッファされている文字列の配列
 10 	 * @type String[]
 11 	 * @private
 12 	 */
 13 	this._str = str?[str]:[];
 14 }
 15 
 16 /**
 17  * バッファに文字列を追加する。
 18  * @param {String} str バッファリングする文字列
 19  * @return {StringBuffer} このオブジェクトへの参照
 20  */
 21 StringBuffer.prototype.append = function(str) {
 22 	this._str.push(str);
 23 	return this;
 24 };
 25 
 26 /**
 27  * バッファリングされた文字列を結合して返す。
 28  * @return {String} 結合された文字列
 29  */
 30 StringBuffer.prototype.toString = function() {
 31 	return this._str.join("");
 32 };
 33