WEB开发网
开发学院网页设计JavaScript JavaScript的相关继承笔记以及使用外部库实现Java... 阅读

JavaScript的相关继承笔记以及使用外部库实现JavaScript的面向对象特性

 2009-09-11 00:00:00 来源:WEB开发网   
核心提示: →xbObject http://archive.bclary.com/定义超类: _classes.registerClass("Grandpa");定义继承: _classes.registerClass("Parent","Gra

→xbObject     http://archive.bclary.com/

定义超类: _classes.registerClass("Grandpa");

定义继承:  _classes.registerClass("Parent","Grandpa");

   1. 
   2. _classes.registerClass("Grandpa"); 
   3. 
   4. function Grandpa(pName){ 
   5. 
   6.    _classes.defineClass("Grandpa",prototypeFunction); 
   7. 
   8.    this.init(pName);   //init方法接受和构造函数相同的方法 
   9.     
  10.    function prototypeFunction () { 
  11.      Grandpa.prototype.init =  function (pName) { 
  12.        this.parentMethod("init");   //parentMethod方法可以传递多个参数,第一个参数为要调用的父类方法名字,然后其他参数被传递给此方法 
  13.        this.name = pName; 
  14.      } 
  15. 
  16.      Grandpa.prototype.saynName =  function () { 
  17.          alert(this.name); 
  18.      } 
  19.    } 
  20. } 
  21. 
  22. _classes.registerClass("Parent","Grandpa"); 
  23. function Parent(pName,cNumber){ 
  24. 
  25.    _classes.defineClass("Parent",prototypeFunction); 
  26. 
  27.    this.init(pName,cNumber);   //init方法接受和构造函数相同的方法 
  28.     
  29.    function prototypeFunction () { 
  30.        Parent.prototype.init =  function (pName,cNumber) { 
  31.        this.parentMethod("init");  
  32.        this.name = pName; 
  33.        this.number = cNumber; 
  34.      } 
  35. 
  36.       Parent.prototype.sayMyName =  function () { 
  37.          alert(this.name); 
  38.      } 
  39. 
  40.       Parent.prototype.sayMyNumber =  function () { 
  41.          alert(this.number); 
  42.      } 
  43.    } 
  44. }

出处:http://hidehai.blog.51cto.com/307955/199163

上一页  1 2 3 4 5 6 

Tags:JavaScript 相关 继承

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接