setup
Perform initialization logic for a constructor function.
Construct.setup(base, fullName, staticProps, protoProps)
A static setup
method provides inheritable setup functionality
for a Constructor function. The following example
creates a Group constructor function. Any constructor
functions that inherit from Group will be added to
Group.childGroups
.
Group = Construct.extend({
setup: function(Construct, fullName, staticProps, protoProps){
this.childGroups = [];
if(Construct !== Construct){
this.childGroups.push(Construct)
}
Construct.setup.apply(this, arguments)
}
},{})
var Flock = Group.extend(...)
Group.childGroups[0] //-> Flock
Parameters
- base
{constructor}
:The base constructor that is being inherited from.
- fullName
{String}
:The name of the new constructor.
- staticProps
{Object}
:The static properties of the new constructor.
- protoProps
{Object}
:The prototype properties of the new constructor.
The static setup
method is called immediately after a constructor
function is created and
set to inherit from its base constructor. It is useful for setting up
additional inheritance work.
Do not confuse this with the prototype setup
method.
Example
This Parent
class adds a reference to its base class to itself, and
so do all the classes that inherit from it.
Parent = Construct.extend({
setup : function(base, fullName, staticProps, protoProps){
this.base = base;
// call base functionality
Construct.setup.apply(this, arguments)
}
},{});
Parent.base; // Construct
Child = Parent({});
Child.base; // Parent