Simulate class inheritance using javascript's prototypical inheritance
Methods
# static addMethods(source, isStatic) → {Class}
Add/Overload class members
Parameters:
Name | Type | Description |
---|---|---|
source |
Object
|
Members to be added to current class |
isStatic |
Boolean
|
Whether the members are static or instance members |
- Deprecated:
- Yes
Class
# static addStaticMethods(source) → {Class}
Add/Override static members
Parameters:
Name | Type | Description |
---|---|---|
source |
Object
|
Static members to be added to current class |
- Deprecated:
- Yes
Class
# static create(parentClassopt, {interfaces}, staticMember, instanceMemberopt) → {Class}
Creates a class and returns a constructor function for instances of the class. Calling the constructor function (typically as part of a new statement) will invoke the class's init method.
If a subclass overrides an instance method declared in a superclass, the subclass's method can still access the original method. To do so, call this._super which is available within the overrided method.
To extend a class after it has been defined, use module:base/klass.addMethods.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
parentClass |
Class
|
<optional> |
Parent class to inherit from. |
{interfaces} |
Array.<base/Interface>
|
Interfaces to implement. |
|
staticMember |
Object
|
Static members of the class. For function, it will be executed and the returned object will be used. |
|
instanceMember |
Object
|
<optional> |
Instance members of the class. For function, it will be executed and the returned object will be used. |
the created class' constructor
Class
Example
klass.create(ParentClass, [
"MyInterface1",
"MyInterface2"
],
{
// Static declarations
...
},{
// Member declarations
//constructor method
init:function(opts) {
this._super(opts); //calling super class method
}
});
# static createAbstract(parentClassopt, {interfaces}, staticMember, instanceMemberopt) → {Class}
create an abstract class. The different between create and createAbstract is abstract class won't check if any abstract function or interface that not implement. The class inherit from abstract class need to implement all the abstractFn from the abstract class. Otherwise, error will be thrown.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
parentClass |
Class
|
<optional> |
Parent class to inherit from. |
{interfaces} |
Array.<base/Interface>
|
Interfaces to implement. |
|
staticMember |
Object
|
Static members of the class. For function, it will be executed and the returned object will be used. |
|
instanceMember |
Object
|
<optional> |
Instance members of the class. For function, it will be executed and the returned object will be used. |
the created class' constructor
Class
Example
klass.createAbstract(ParentClass, [
"MyInterface1",
"MyInterface2"
],
{
// Static declarations
...
},{
// Member declarations
//constructor method
init:function(opts) {
this._super(opts); //calling super class method
}
});