新的起點(diǎn) 新的開(kāi)始

          快樂(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 閱讀(252) 評(píng)論(0)  編輯  收藏 所屬分類: 腳本

          公告

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

          統(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)論排行榜

          主站蜘蛛池模板: 灵山县| 阿勒泰市| 同心县| 甘泉县| 运城市| 贺州市| 惠东县| 通河县| 平南县| 通江县| 凉城县| 博兴县| 辉县市| 唐山市| 米易县| 双柏县| 昆明市| 石泉县| 宣威市| 洛南县| 益阳市| 鄄城县| 绥棱县| 奉化市| 乌恰县| 和平区| 石屏县| 湘乡市| 饶河县| 浪卡子县| 泸水县| 如东县| 高雄县| 金华市| 秦安县| 北宁市| 合川市| 陕西省| 泽州县| 孝义市| 当涂县|