<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
    主站蜘蛛池模板: 亚洲精品蜜桃久久久久久| 最近中文字幕mv手机免费高清| 特a级免费高清黄色片| 亚洲精品无AMM毛片| 国产成人亚洲合集青青草原精品 | 动漫黄网站免费永久在线观看| 69精品免费视频| 精品无码AV无码免费专区| 24小时日本韩国高清免费| 久久久久免费看成人影片| 1000部夫妻午夜免费| 我们的2018在线观看免费高清| 精品国产污污免费网站aⅴ| 免费精品国产自产拍在| 蜜桃视频在线观看免费网址入口| 国产人成免费视频网站| 免费看成人AA片无码视频羞羞网| 成人特黄a级毛片免费视频| 在线免费观看a级片| 免费a级毛片18以上观看精品| 亚洲国产精品一区二区第四页| 亚洲色婷婷综合开心网| 久久亚洲国产中v天仙www| 亚洲黄网站wwwwww| 亚洲制服丝袜中文字幕| 成a人片亚洲日本久久| 一级做性色a爰片久久毛片免费| 国产线视频精品免费观看视频| 大地资源网高清在线观看免费| 一级毛片在线免费看| 国产精品久久久久免费a∨| 国产精品国产午夜免费福利看 | 51在线视频免费观看视频| 德国女人一级毛片免费| 免费成人午夜视频| 亚洲AV无码一区二区二三区软件| 亚洲国产美女视频| 精品亚洲福利一区二区| 羞羞视频免费网站日本| 亚洲乱人伦中文字幕无码| 国产亚洲福利一区二区免费看 |