< The Science of Programming < SwayPresentations < Objects
Variation Inheritance
Variation inheritance: whereby the subclass changes a behavior of the super class.
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());
The output is:
well, hello there!
Looking at the s object gives:
<OBJECT 2611>: context: <OBJECT 654> dynamicContext: <OBJECT 654>
callDepth: 1
constructor: <function sub()>
this: <OBJECT 2611>
a: <function a()>
a: <function a()>
greeting: "hello"
This article is issued from Wikibooks. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.