隨筆:25 文章:1 評論:8 引用:0
          BlogJava 首頁 發新隨筆
          發新文章 聯系 聚合管理

          2010年5月6日

          for a C++ program converts true and false to 1 and 0 where integer values are expected, and it converts 0 to false and nonzero to true where bool values are expected.
          posted @ 2010-05-22 00:23 ljwiie 閱讀(158) | 評論 (0)編輯 收藏
           
          用構造函數定義屬性,用原型定義方法
          function ClassA(sColor) {
              this.color = sColor;
          }

          ClassA.prototype.sayColor = function () {
              alert(this.color);
          };

          function ClassB(sColor, sName) {
              ClassA.call(this, sColor);
              this.name = sName;
          }

          ClassB.prototype = new ClassA();

          ClassB.prototype.sayName = function () {
              alert(this.name);
          };
          在此例子中,繼承機制由兩行突出顯示的藍色代碼實現。在第一行突出顯示的代碼中,在 ClassB 構造函數中,用對象冒充繼承 ClassA 類的 sColor 屬性。在第二行突出顯示的代碼中,用原型鏈繼承 ClassA 類的方法。由于這種混合方式使用了原型鏈,所以 instanceof 運算符仍能正確運行。

          下面的例子測試了這段代碼:
          var objA = new ClassA("blue");
          var objB = new ClassB("red", "John");
          objA.sayColor(); //輸出 "blue"
          objB.sayColor(); //輸出 "red"
          objB.sayName(); //輸出 "John"

          摘自http://www.w3school.com.cn/js/pro_js_inheritance_implementing.asp
          posted @ 2010-05-06 23:57 ljwiie 閱讀(202) | 評論 (1)編輯 收藏
          CALENDER
          <2010年5月>
          2526272829301
          2345678
          9101112131415
          16171819202122
          23242526272829
          303112345

          常用鏈接

          留言簿(1)

          隨筆分類

          隨筆檔案

          相冊

          收藏夾

          朋友blog

          最新評論


          Powered By: 博客園
          模板提供滬江博客

          Contact ljwiie QQ:122050271
          主站蜘蛛池模板: 南丹县| 云阳县| 获嘉县| 历史| 荆州市| 武冈市| 曲阳县| 定远县| 千阳县| 宜兰县| 泽州县| 探索| 屏边| 红河县| 邵阳县| 胶州市| 胶南市| 临泉县| 于田县| 什邡市| 武夷山市| 盘锦市| 民乐县| 庆安县| 丁青县| 阿拉善右旗| 丰都县| 游戏| 邹平县| 阿拉尔市| 金华市| 西林县| 蒲城县| 周宁县| 望谟县| 潮安县| 大足县| 荣昌县| 南雄市| 广丰县| 徐汇区|