String Buffer implementation in JavaScript