科学编程/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"