跳轉到內容

科學程式設計/SwayPresentations/物件/變差傳承

來自華夏公益教科書,開放書籍,面向開放世界

變差傳承

變差傳承:子類改變了超類的行為。

   function super()
       {
       var greeting = "hello";
       function a() { greeting; }
       this;
       }
   
   function sub()
       {
       function a() { "well, " + a . prior() + " there!"; }
       extends(super());
       }
   
   var s = sub();
   
   println(s . a());

輸出是

   well, hello there!

檢視s物件會返回

   <OBJECT 2611>:
       context: <OBJECT 654>
       dynamicContext: <OBJECT 654>
       callDepth: 1
       constructor: <function sub()>
       this: <OBJECT 2611>
       a: <function a()>
       a: <function a()>
       greeting: "hello"

下一步 上一步 頂部

華夏公益教科書