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();

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

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)

  • [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.

Returns: <Function>

a class definition

public void events ([args])

Extends zebkit.Class with the given events support.

  • [args] <String> (*..n)

    list of events names

public void extend ([interfaces], methods)

Extend the class with new method and implemented interfaces.

  • [interfaces] <zebkit.Interface> (*..n)

    number of interfaces the class has to implement.

  • methods <Array>

    set of methods the given class has to be extended.

public <Function> forName (name)

Get class by the given class name

Returns: <Function>

a class. Throws exception if the class cannot be resolved by the given class name



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.

Returns: <Boolean>

true if the class or interface is inherited with the class.

public <Object> newInstance ([arguments])

Create an instance of the class

  • [arguments] <Object> (*..n)

    arguments to be passed to the class constructor

Returns: <Object>

an instance of the class.

private <String> $hash$

Unique string hash code. The property is not defined if the class was not maid hashable by calling "hashable()" method.

protected <zebkit.Class> $parent

Reference to a parent class

private <Object> $parents

Dictionary of all inherited interfaces where key is unique interface hash code and the value is interface itself.

private <Object> $propertyInfo

Internal attribute that caches properties setter references.

public <zebkit.Class> clazz

The instance class.