Version0 /
ExtendAn accessor may specify that it extends another accessor in its
This has the effect of implementing the interface of the other accessor, as if implement had been invoked, but in addition, it inherits all exported fields and functions of the specified accessor. For example, suppose a base accessor exports.initialize = function() { console.log('Initialize base accessor.'); } Then if an accessor specifies the following: exports.setup = function() { extend("MyBase"); } then it will inherit the An accessor may override any exported function of the base accessor by simply defining a function with the same name. Moreover, the override function can invoke the overridden function as in the following example: exports.initialize = function() { this.ssuper.initialize(); console.log('Initialize extended accessor.'); }; When the Initialize base accessor. Initialize extended accessor. An accessor can also override input handler functions. Suppose that a Base accessor has the following: exports.inputHandler = function() { // Send true to output. send('output', true); } exports.initialize = function() { addInputHandler('input', this.inputHandler); } Then a Derived accessor that extends this base can override the input handler with the following code: exports.inputHandler = function() { // Send false to output instead. send('output', false); } exports.initialize = function() { this.ssuper.initialize.apply(this); } In an instance of Derived, when an input arrives on 'input', the accessor will send addInputHandler('input', this.inputHandler); The use of the keyword addInputHandler('input', exports.inputHandler); then the override would not succeed. Here, A derived accessor may modify the options of the inputs, outputs, and parameters of the extended accessor. For example, if ``MyBase``` has a parameter named 'foo', then exports.setup = function() { extend('MyBase'); parameter('foo', {'value':43}); } modifies the default value of 'foo' from whatever it is in the base to 43. See Support for implement and extend in Ptolemy II. |