新的起點(diǎn) 新的開始

          快樂(lè)生活 !

          js實(shí)相繼承小例

          本文通過(guò)混合構(gòu)造函數(shù)于原型方式來(lái)實(shí)現(xiàn)JS的繼承功能。 Polygon為父類,Triangle Rectangle 為子類。
          function Polygon (iSiders){
              this.sides = iSiders;
          }
          Polygon.prototype.getArea = function(){
              return 0;
          }


          function Triangle(iBase,iHeight){
              Polygon.call(this,3);
              this.base = iBase;
              this.height = iHeight;
          }
          Triangle.prototype = new Polygon();
          Triangle.prototype.getArea = function(){
              return 0.5*this.base*this.height;
          }

          function Rectangle(iLength,iWidth){
              Polygon.call(this,4);
              this.length = iLength;
              this.width = iWidth;
          }
          Rectangle.prototype = new Polygon();
          Rectangle.prototype.getArea = function(){
              return this.length*this.width;
          }
          var triangle = new Triangle(12,4);
          var rectangle = new Rectangle(22,10);
          alert(triangle.getArea);
          alert(rectangle.getArea);

          posted on 2007-04-10 14:23 advincenting 閱讀(249) 評(píng)論(0)  編輯  收藏 所屬分類: 腳本

          公告

          Locations of visitors to this pageBlogJava
        1. 首頁(yè)
        2. 新隨筆
        3. 聯(lián)系
        4. 聚合
        5. 管理
        6. <2025年5月>
          27282930123
          45678910
          11121314151617
          18192021222324
          25262728293031
          1234567

          統(tǒng)計(jì)

          常用鏈接

          留言簿(13)

          隨筆分類(71)

          隨筆檔案(179)

          文章檔案(13)

          新聞分類

          IT人的英語(yǔ)學(xué)習(xí)網(wǎng)站

          JAVA站點(diǎn)

          優(yōu)秀個(gè)人博客鏈接

          官網(wǎng)學(xué)習(xí)站點(diǎn)

          生活工作站點(diǎn)

          最新隨筆

          搜索

          積分與排名

          最新評(píng)論

          閱讀排行榜

          評(píng)論排行榜

          主站蜘蛛池模板: 扶余县| 九江市| 信宜市| 彰化市| 惠安县| 晋江市| 潢川县| 邵武市| 襄垣县| 拜城县| 南丹县| 荣昌县| 安乡县| 博兴县| 新河县| 开封县| 吉木乃县| 壤塘县| 财经| 子洲县| 扎赉特旗| 江油市| 丰台区| 铅山县| 什邡市| 子洲县| 阳原县| 葫芦岛市| 新兴县| 雅安市| 儋州市| 道孚县| 合山市| 邻水| 洪雅县| 铜鼓县| 江山市| 宁都县| 肃宁县| 屏东县| 竹溪县|