科學程式設計/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"