Class zebkit.Class | <zebkit> |
Core method method to declare a zebkit class following easy OOP approach. The easy OOP concept supports the following OOP features:
Single class inheritance. Any class can extend an another zebkit class
// declare class "A" that with one method "a"
var A = zebkit.Class([
function a() { ... }
]);
// declare class "B" that inherits class "A"
var B = zebkit.Class(A, []);
// instantiate class "B" and call method "a"
var b = new B();
b.a();
Class method overriding. Override a parent class method implementation
// declare class "A" that with one method "a"
var A = zebkit.Class([
function a() { ... }
]);
// declare class "B" that inherits class "A"
// and overrides method a with an own implementation
var B = zebkit.Class(A, [
function a() { ... }
]);
Constructors. Constructor is a method with empty name
// declare class "A" that with one constructor
var A = zebkit.Class([
function () { this.variable = 100; }
]);
// instantiate "A"
var a = new A();
a.variable // variable is 100
Static methods and variables declaration. Static fields and methods can be defined by declaring special "$clazz" method whose context is set to declared class
var A = zebkit.Class([
// special method where static stuff has to be declared
function $clazz() {
// declare static field
this.staticVar = 100;
// declare static method
this.staticMethod = function() {};
}
]);
// access static field an method
A.staticVar // 100
A.staticMethod() // call static method
Access to super class context. You can call method declared in a parent class
// declare "A" class with one class method "a(p1,p2)"
var A = zebkit.Class([
function a(p1, p2) { ... }
]);
// declare "B" class that inherits "A" class and overrides "a(p1,p2)" method
var B = zebkit.Class(A, [
function a(p1, p2) {
// call "a(p1,p2)" method implemented with "A" class
this.$super(p1,p2);
}
]);
One of the powerful feature of zebkit easy OOP concept is possibility to instantiate anonymous classes and interfaces. Anonymous class is an instance of an existing class that can override the original class methods with own implementations, implements own list of interfaces and methods. In other words the class instance customizes class definition for the particular instance of the class;
// declare "A" class
var A = zebkit.Class([
function a() { return 1; }
]);
// instantiate anonymous class that add an own implementation of "a" method
var a = new A([
function a() { return 2; }
]);
a.a() // return 2
zebkit.Class
([inheritedClass], [inheritedInterfaces], methods
)
Parameters:
-
[inheritedClass]
<zebkit.Class>an optional parent class to be inherited
-
[inheritedInterfaces]
<zebkit.Interface> (*..n)an optional list of interfaces for the declared class to be mixed in the class
-
methods
<Array>list of declared class methods. Can be empty array.
a class definition
public | void | events ([args]) |
public | void | extend ([interfaces], methods) |
public | <Function> | forName (name) |
public | void | hashable ( ) |
public | void | hashless ( ) |
public | <Boolean> | isInherit (clazz) |
public | <Object> | newInstance ([arguments]) |
public | <Object> | newInstancea (args) |
public
void
events ([args] )
Extends zebkit.Class with the given events support. Parameters:
|
public
chainable
extend ([interfaces], methods )
Extend the class with new method and implemented interfaces. Parameters:
|
public
chainable
hashable ( )
Makes the class hashable. Hashable class instances are automatically gets unique hash code that is returned with its overridden "toString()" method. The hash code is stored in special "$hash$" field. The feature can be useful when you want to store class instances in "{}" object where key is the hash and the value is the instance itself. |
public
chainable
hashless ( )
Makes the class hashless. Prevents generation of hash code for instances of the class. |
public
<Boolean>
isInherit (clazz )
Tests if the class inherits the given class or interface. Parameters:
Returns:
<Boolean>
true if the class or interface is inherited with the class. |