|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object zk.Object zk.Class
public class Class
Represents a class. It is the metainfo about a class. The class of each object can be accessed by zk.Object#$class. All static members can be retrieve from this class. For example,
MyClass = zk.$extends{zk.Object, {
},{
find: function (name) {
}
});
foo = new MyClass();
where the following two statement are equivalent.
foo.$class.find('abc');
MyClass.find('abc');
Like Java, all classes objects have #isAssignableFrom and #isInstance. Unlike Java, all static methods are available as a method of the class object, including the superclass's static methods.
MyClass = zk.$extends(zk.Object, {}, {
static0: function () {}
});
MyDerive = zk.$extends(zk.Object, {}, {
static1: function () {}
});
MyDerive.static0(); //OK
MyDerive.static1(); //OK
Unlike Java, you cannot access the static methods by an object. Rather, you have to go thru the class object
var md = new MyDerive();
md.static0(); //Fail
md.static1(); //Fail
md.$class.static0(); //OK
MyDerive.static0(); //OK
Unlike Java, the class can by accessed directly, such as o.$instanceof(MyClass). In addition, the class objects are not instances of a particular class (Class in Java).
o.$class.$instanceof(zk.Class); //wrong! no zk.Class
Unlike Java, if a static method of the class has the same name of a static method of the superclass, it 'overrides' it.
MyClass = zk.$extends(zk.Object, {}, {
static0: function () {}
});
MyDerive = zk.$extends(zk.Object, {}, {
static0: function () {}
});
var mc = new MyClass(), md = new MyDerive();
mc.static0(); //invoke MyClass.static0
md.static0(); //invoke MyDerive.static0
In additions, the static members are placed in different scope from the non-static members. Thus, it is OK that a static member has the same name as a non-static member, though it is not a good practice (due to confusion to users).
Like Java's Class.forName
, you can use zk.$import(_global_.String, _global_.Function)
to resolve the class from the class name.
Field Summary |
---|
Fields inherited from class zk.Object |
---|
$class, $oid |
Method Summary | |
---|---|
boolean |
isAssignableFrom(Class klass)
Determines if the class by this Class object is either the same as, or is a superclass of, the class represented by the specified Class parameter. |
boolean |
isInstance(Object obj)
Determines if the specified Object is assignment-compatible with this Class. |
Methods inherited from class zk.Object |
---|
$init, $instanceof, $super, $super, $supers, $supers, afterInit, proxy |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method Detail |
---|
public boolean isAssignableFrom(Class klass)
if (klass1.isAssignableFrom(klass2)) {
}
isAssignableFrom
in class Object
klass
- the Class object to be checked
public boolean isInstance(Object obj)
if (klass.isInstance(obj)) {
}
isInstance
in class Object
obj
- the object to be checked
isAssignableFrom(zk.Class)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |