案例:JavaScript案例     状态:可编辑再运行    进入竖版
 运行结果 
x
 
1
<html>
2
<body>
3
4
<script type="text/javascript">
5
6
function StringBuffer () {
7
  this._strings_ = new Array();
8
}
9
10
StringBuffer.prototype.append = function(str) {
11
  this._strings_.push(str);
12
};
13
14
StringBuffer.prototype.toString = function() {
15
  return this._strings_.join("");
16
};
17
18
var buffer = new StringBuffer ();
19
buffer.append("hello ");
20
buffer.append("world");
21
var result = buffer.toString();
22
23
document.write(buffer);
24
25
</script>
26
27
</body>
28
</html>
29