<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    Alex刺客

    Dancing fingers, damage world. -- 舞動手指,破壞世界.

      BlogJava :: 首頁 :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理 ::
      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高級程序設(shè)計.pdf -> 第四章 -> 4.2.1 繼承的方式
     9            *    練習(xí)者: Alex刺客
    10            *    日期: 2009-12-13
    11            */

    12            
    13            /*
    14                1.對象冒充
    15            */

    16            //ClassA類
    17            function ClassA (sColor) {
    18                this.color = sColor;
    19                this.sayColor = function () {
    20                        alert(this.color);
    21                    }

    22            }

    23            
    24            //ClassB類
    25            function ClassB(sColor,sName){
    26                //當(dāng)前對象的屬性是ClassA函數(shù)的指針
    27                this.newMethod = ClassA;
    28                //把參數(shù)傳遞給它
    29                this.newMethod(sColor);
    30                //刪除當(dāng)前對象的ClassA函數(shù)的指針
    31                delete this.newMethod;
    32                
    33                //新增屬性和方法
    34                this.name = sName;
    35                this.sayName = function () {
    36                    alert(this.name);
    37                }

    38            }

    39            
    40            //var cb = new ClassB("blue!","Redboy");
    41            //cb.sayColor();
    42            //cb.sayName();
    43            
    44            /*
    45                call()方法
    46                call()方法與對象冒充方法最相似。它的第一個參數(shù)用作this的對象。
    47                其他參數(shù)都直接傳遞給函數(shù)自身。
    48            */

    49            //ClassC類
    50            function ClassC(sColor,sName){
    51                //this.newMethod = ClassA;
    52                //this.newMethod(sColor);
    53                //delete this.newMethod;
    54                ClassA.call(this,sColor); //以上三行代碼由這行替代
    55                
    56                //新增屬性和方法
    57                this.name = sName;
    58                this.sayName = function () {
    59                    alert(this.name);
    60                }

    61            }

    62            
    63            //var cc = new ClassC("blue","c");
    64            //cc.sayColor();
    65            //cc.sayName();
    66            
    67            /*
    68                apply()方法
    69                apply()方法有兩個參數(shù),跟call()方法相似,只是第二個參數(shù)變成了數(shù)組。
    70            */

    71            //ClassD類
    72            function ClassD(sColor,sName){
    73                //this.newMethod = ClassA;
    74                //this.newMethod(sColor);
    75                //delete this.newMethod;
    76                ClassA.apply(this,new Array(sColor)); //以上三行代碼由這行替代
    77                
    78                //新增屬性和方法
    79                this.name = sName;
    80                this.sayName = function () {
    81                    alert(this.name);
    82                }

    83            }

    84            
    85            //var dt = new ClassD("red","blueBoy");
    86            //dt.sayColor();
    87            //dt.sayName();
    88            
    89        </script>
    90    </head>
    91    <body>
    92    </body>
    93</html>
    posted on 2009-12-13 23:10 Alex刺客 閱讀(257) 評論(0)  編輯  收藏 所屬分類: JavaScript
    主站蜘蛛池模板: 国产亚洲?V无码?V男人的天堂 | 野花高清在线观看免费完整版中文 | 国产极品粉嫩泬免费观看| 亚洲人成免费电影| 日本XXX黄区免费看| 亚洲国产精品无码久久久| 亚洲免费福利在线视频| 国产婷婷综合丁香亚洲欧洲| 久久精品无码一区二区三区免费 | 色欲aⅴ亚洲情无码AV| 免费一级大黄特色大片| 色屁屁在线观看视频免费| 亚洲精品456播放| 在线观看肉片AV网站免费| 久久精品国产亚洲AV果冻传媒| 日本一卡精品视频免费| 亚洲伊人久久大香线蕉结合| 日韩午夜免费视频| 一区二区视频免费观看| 久久精品国产亚洲av四虎| 亚洲一区二区免费视频| 亚洲av纯肉无码精品动漫| 亚洲色婷婷综合开心网| 久久免费公开视频| 亚洲日韩国产精品乱-久| 日韩免费视频观看| 成在线人免费无码高潮喷水| 亚洲欧洲国产日韩精品| 毛片a级毛片免费播放下载| 青青草97国产精品免费观看| 亚洲Av熟妇高潮30p| 日韩成人在线免费视频| 精品无码国产污污污免费网站国产| 亚洲电影国产一区| 国产精品va无码免费麻豆| a在线观看免费网址大全| 亚洲精品免费网站| 亚洲午夜国产精品无码| 最近中文字幕mv免费高清视频7 | 国产午夜无码精品免费看动漫| 亚洲fuli在线观看|