public class Class extends Object
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(MyClass, {}, {
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(MyClass, {}, {
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.
Modifier and Type | Method and Description |
---|---|
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.
|
public boolean isAssignableFrom(Class klass)
if (klass1.isAssignableFrom(klass2)) {
}
isAssignableFrom
in class Object
klass
- the Class object to be checkedpublic boolean isInstance(Object obj)
if (klass.isInstance(obj)) {
}
isInstance
in class Object
obj
- the object to be checkedisAssignableFrom(zk.Class)
Copyright © 2005-2023 Potix Corporation. All Rights Reserved.