Alex刺客

Dancing fingers, damage world. -- 舞动手指,破坏世界.

  BlogJava :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理 ::
  57 随笔 :: 0 文章 :: 76 评论 :: 0 Trackbacks
 1<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 2<html xmlns="http://www.w3.org/1999/xhtml">
 3    <head>
 4        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
 5        <title>实例</title>
 6        <script type="text/javascript">
 7            /*
 8            *    项目: book -> Javascript高级程序设计.pdf -> 第3章 -> 3.5.8实例
 9            *
10            *    说明:自定义对象的使用
11            *
12            *    练习者: Alex刺客
13            *
14            *    日期: 2009-12-13
15            */

16
17            /*
18                定义一个一次合并当前对象所有字符串的StringBuffer类
19            */

20            
21            function StringBuffer () {
22                this._strings_ = new Array;
23                if (typeof StringBuffer._initialized == "undefined"{
24                    StringBuffer.prototype.append = function (str){
25                        this._strings_.push(str);
26                    }

27                    StringBuffer.prototype.toString = function(){
28                        return this._strings_.join("");
29                    }

30                }

31            }

32            
33            var stringBufferTest = new StringBuffer();
34            var string2 = new StringBuffer();
35            stringBufferTest.append("Hello ");
36            stringBufferTest.append("World! ");
37            stringBufferTest.append("Welcome");
38            stringBufferTest.append("to ");
39            stringBufferTest.append("JavaScript! ");
40            string2.append("Alex ");
41            string2.append("刺客!");
42            var result = stringBufferTest.toString();
43            var test = string2.toString();
44            alert(result);
45            alert(test);
46        </script>
47    </head>
48    <body>
49    </body>
50</html>
posted on 2009-12-13 22:54 Alex刺客 阅读(182) 评论(0)  编辑  收藏 所属分类: JavaScript

只有注册用户登录后才能发表评论。


网站导航: