Package zebkit |
This is the core package that provides powerful easy OOP concept, packaging and number of utility methods. The package doesn't have any dependencies from others zebkit packages and can be used independently. Briefly the package possibilities are listed below:
- easy OOP concept. Use "zebkit.Class" and "zebkit.Interface" to declare classes and interfaces
// declare class A
var ClassA = zebkit.Class([
function() { // class constructor
...
},
// class method
function a(p1, p2, p3) { ... }
]);
var ClassB = zebkit.Class(ClassA, [
function() { // override cotoString.nanstructor
this.$super(); // call super constructor
},
function a(p1, p2, p3) { // override method "a"
this.$super(p1, p2, p3); // call super implementation of method "a"
}
]);
var b = new ClassB(); // instantiate classB
b.a(1,2,3); // call "a"
// instantiate anonymous class with new method "b" declared and
// overridden method "a"
var bb = new ClassB([
function a(p1, p2, p3) { // override method "a"
this.$super(p1, p2, p3); // call super implementation of method "a"
},
function b() { ... } // declare method "b"
]);
b.a();
b.b();
- Packaging. Zebkit uses Java-like packaging system where your code is bundled in the number of hierarchical packages.
// declare package "zebkit.test"
zebkit.package("test", function(pkg) {
// declare class "Test" in the package
pkg.Test = zebkit.Class([ ... ]);
});
...
// Later on use class "Test" from package "zebkit.test"
zebkit.require("test", function(test) {
var test = new test.Test();
});
- Resources loading. Resources should be loaded with a special method to guarantee its proper loading in zebkit sequence and the loading completeness.
// declare package "zebkit.test"
zebkit.resources("http://my.com/test.jpg", function(img) {
// handle completely loaded image here
...
});
zebkit.package("test", function(pkg, Class) {
// here we can be sure all resources are loaded and ready
});
- Declaring number of core API method and classes
- "zebkit.DoIt" - improves Promise like alternative class
- "zebkit.URI" - URI helper class
- "zebkit.Dummy" - dummy class
- instanceOf(...) method to evaluate zebkit classes and and interfaces inheritance. The method has to be used instead of JS "instanceof" operator to provide have valid result.
- zebkit.newInstance(...) method
- zebkit.clone(...) method
- etc
private
|
<Object> | $cache (key) |
public | <Object> | clone (obj) |
public | void | dumpError (e) |
public | void | findInTree (root, path, cb, [eq]) |
public | <Function> | getPropertyGetter (obj, name) |
public | <Function> | getPropertySetter (obj, name) |
public | <Object> | getPropertyValue (obj, path, [useGetter]) |
public | <zebkit.DoIt> | image (ph, [fireErr]) |
public | <Boolean> | instanceOf (obj, clazz) |
public | <Boolean> | isAtomic (v) |
public | <Boolean> | isBoolean (v) |
public | <Boolean> | isNumber (v) |
public | <Boolean> | isString (v) |
public | <zebkit.Listener> | ListenersClass ([events]) |
public | <Object> | newInstance (clazz, [args]) |
public | <Object> | properties (target, props) |
private
<Object>
$cache (key )
Get an object by the given key from cache (and cached it if necessary) Parameters:
Returns:
<Object>
an object |
public
<Object>
clone (obj )
Clone the given object. The method tries to perform deep cloning by traversing the given object structure recursively. Any part of an object can be marked as not cloneable by adding "$notCloneable" field that equals to true. Also at any level of object structure the cloning can be customized with adding "$clone" method. In this case the method will be used to clone the part of object. clonable Parameters:
Returns:
<Object>
a cloned object |
public
void
dumpError (e )
Dump the given error to output. Parameters:
|
public
void
findInTree (root, path, cb, [eq] )
Finds an item by xpath-like simplified expression applied to a tree-like structure. Passed tree-like structure doesn't have a special requirements except every item of the structure have to define its kids by exposing "kids" field. The field is array of children elements:
The find method traverse the tree-like structure according to the xpath-like expression. To understand if the given tree item confronts with the currently traversing path fragment a special equality method has to be passed. The method gets the traversing tree item and a string path fragment. The method has to decide if the given tree item complies the specified path fragment. Parameters:
|
public
<Function>
getPropertyGetter (obj, name )
Get a property getter method if it is declared with the class of the specified object for the
given property. Getter is a method whose name matches the following patterns: "get Parameters:
Returns:
<Function>
a method that can be used as a getter for the given property |
public
<Function>
getPropertySetter (obj, name )
Get a property setter method if it is declared with the class of the specified object for the
given property. Setter is a method whose name matches the following pattern: "set Parameters:
Returns:
<Function>
a method that can be used as a setter for the given property |
public
<Object>
getPropertyValue (obj, path, [useGetter] )
Get property value for the given object and the specified property path Parameters:
Returns:
<Object>
a property value, return undefined if property cannot be found |
public
<zebkit.DoIt>
image (ph, [fireErr] )
Load image or complete the given image loading. Parameters:
Returns:
<zebkit.DoIt>
|
public
<Boolean>
instanceOf (obj, clazz )
Test if the given object is instance of the specified class or interface. It is preferable to use this method instead of JavaScript "instanceof" operator whenever you are dealing with zebkit classes and interfaces. Parameters:
Returns:
<Boolean>
true if a passed object is instance of the given class or interface |
public
<zebkit.Listener>
ListenersClass ([events] )
This method allows to declare a listeners container class for the given dedicated event types.
Parameters:
Returns:
<zebkit.Listener>
a listener container class |
public
<Object>
properties (target, props )
Populate the given target object with the properties set. The properties set is a dictionary that keeps properties names and its corresponding values. Applying of the properties to an object does the following:
Parameters:
Returns:
<Object>
an object with the populated properties set. |