computer programming

javascript -> StringBuffer

stekilove 2007. 12. 17. 17:06

JavaScript StringBuffer

function StringBuffer() { this.buffer = []; }

StringBuffer.prototype.append = function(string)
{
this.buffer.push(string);
return this;
}

StringBuffer.prototype.toString = function()
{
return this.buffer.join("");
}

To use it:
var s = new StringBuffer();
s.append("Hello, ").append(" World!");
alert(s.toString());
link:
http://www.multitask.com.au/people/dion/archives/000354.html