Wednesday, May 30, 2007

JavaScript StringBuffer like java StringBuffer object

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

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

StringBuffer.prototype.toString = function()
{ 
  return this.buffer.join(""); 
}
Usage: var s = new StringBuffer(); s.append("Hello, ").append(" World!"); alert(s.toString());
 
Blogger Template Layout Design by [ METAMUSE ] : Code Name Gadget 1.1 Power By freecode-frecode.blogger.com & blogger.com Programming Blogs - BlogCatalog Blog Directory