zk
Class Object

java.lang.Object
  extended by zk.Object
Direct Known Subclasses:
BigDecimal, Class, Color, ContentHandler, Draggable, DropUploader, DropUploadViewer, Event, FullMask, ItemIter, Long, Mask, RowIter, Scrollbar, Shadow, SimpleConstraint, Skipper, Swipe, TreeItemIter, Upload, Uploader, UploadViewer, Widget, WScroll

public class Object
extends java.lang.Object

The root of the class hierarchy.

See Also:
Class

Field Summary
 Class $class
          The class that this object belongs to.
 int $oid
          The object ID.
 
Method Summary
 void $init()
          The constructor.
 boolean $instanceof(Class klass)
          Determines if this object is an instance of the class represented by the specified Class parameter.
 Object $super(Class klass, String mtd, Object... vararg)
          Invokes a method defined in the superclass with any number of arguments.
 Object $super(String mtd, Object... vararg)
          Invokes a method defined in the superclass with any number of arguments.
 Object $supers(Class klass, String mtd, Array args)
          Invokes a method defined in the superclass with an array of arguments.
 Object $supers(String mtd, Array args)
          Invokes a method defined in the superclass with an array of arguments.
 void afterInit(Function func)
          Specifies a function that shall be called after the object is initialized, i.e., after $init() is called.
static boolean isAssignableFrom(Class cls)
          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.
static boolean isInstance(Object o)
          Determines if the specified Object is assignment-compatible with this Class.
 Function proxy(Function func)
          Proxies a member function such that it can be called with this object in a context that this object is not available.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

$class

public Class $class
The class that this object belongs to.


$oid

public int $oid
The object ID. Each object has its own unique $oid. It is mainly used for debugging purpose.

Trick: you can test if a JavaScript object is a ZK object by examining this property, such as if (o.$oid) alert('o is a ZK object');

Notice: zk.Class extends from zk.Object (so a class also has $oid)

Method Detail

afterInit

public void afterInit(Function func)
Specifies a function that shall be called after the object is initialized, i.e., after $init() is called. This method can be called only during the execution of $init().

It is an advance feature that is used to allow a base class to do something that needs to wait for all deriving classes have been initialized.

Invocation Sequence:

Parameters:
func - the function to register for execution later
See Also:
$init()

$instanceof

public boolean $instanceof(Class klass)
Determines if this object is an instance of the class represented by the specified Class parameter. Example:

if (obj.$instanceof(zul.wgt.Label, zul.wgt.Image)) {
}

Parameters:
klass - the Class object to be checked. Any number of arguments can be specified.
Returns:
boolean true if this object is an instance of the class

$super

public Object $super(Class klass,
                     String mtd,
                     Object... vararg)
Invokes a method defined in the superclass with any number of arguments. It is like Function's call() that takes any number of arguments.

It is similar to $super(String, Object...), but this method works even if the superclass calls back the same member method. In short, it is tedious but safer.

Example:


foo.MyClass = zk.$extends(foo.MySuper, {
  multiply: function (n) {
   return this.$super(foo.MyClass, 'multiply', n + 2);
  }

Notice that the class specified in the first argument is not the super class having the method. Rather, it is the class that invokes this method.

Parameters:
klass - the class that invokes this method.
mtd - the method name to invoke
vararg - any number of arguments
Returns:
Object the object being returned by the method of the superclass.
Since:
5.0.2
See Also:
$supers(zk.Class, _global_.String, _global_.Array)

$super

public Object $super(String mtd,
                     Object... vararg)
Invokes a method defined in the superclass with any number of arguments. It is like Function's call() that takes any number of arguments.

Example:


multiply: function (n) {
 return this.$super('multiply', n + 2);
}

Parameters:
mtd - the method name to invoke
vararg - any number of arguments
Returns:
Object the object being returned by the method of the superclass.
See Also:
$supers(zk.Class, _global_.String, _global_.Array)

$supers

public Object $supers(Class klass,
                      String mtd,
                      Array args)
Invokes a method defined in the superclass with an array of arguments. It is like Function's apply() that takes an array of arguments.

It is similar to $supers(String, Array), but this method works even if the superclass calls back the same member method. In short, it is tedious but safer.

Example:


foo.MyClass = zk.$extends(foo.MySuper, {
  multiply: function () {
   return this.$supers(foo.MyClass, 'multiply', arguments);
  }

Notice that the class specified in the first argument is not the super class having the method. Rather, it is the class that invokes this method.

Parameters:
klass - the class that invokes this method.
mtd - the method name to invoke
args - an array of arguments. In most case, you just pass arguments (the built-in variable).
Returns:
Object the object being returned by the method of the superclass.
Since:
5.0.2
See Also:
$super(zk.Class, _global_.String, zk.Object...)

$supers

public Object $supers(String mtd,
                      Array args)
Invokes a method defined in the superclass with an array of arguments. It is like Function's apply() that takes an array of arguments.

Example:


multiply: function () {
 return this.$supers('multiply', arguments);
}

Parameters:
mtd - the method name to invoke
args - an array of arguments. In most case, you just pass arguments (the built-in variable).
Returns:
Object the object being returned by the method of the superclass.
See Also:
$super(zk.Class, _global_.String, zk.Object...)

proxy

public Function proxy(Function func)
Proxies a member function such that it can be called with this object in a context that this object is not available. It sounds a bit strange at beginning but useful when passing a member of an object that will be executed as a global function.

Example: Let us say if you want a member function to be called periodically, you can do as follows.


setInterval(wgt.proxy(wgt.doIt), 1000); //assume doIt is a member function of wgt

With proxy, when doIt is called, this references to wgt. On the other hand, the following won't work since this doesn't reference to wgt, when doIt is called.


setInterval(wgt.doIt, 1000); //WRONG! doIt will not be called with wgt

Notice that this method caches the result so that it will return the same proxied function, if you pass the same function again.

Parameters:
func - a method member of this object
Returns:
Function a function that can be called as a global function (that actually have this referencing to this object).

$init

public void $init()
The constructor.

Default: it does nothing so the subclass needs not to copy back (also harmless to call back).

See Also:
afterInit(_global_.Function)

isInstance

public static boolean isInstance(Object o)
Determines if the specified Object is assignment-compatible with this Class. This method is equivalent to [[zk.Object#$instanceof]. Example:

if (klass.isInstance(obj)) {
}

Parameters:
o - the object to check
Returns:
boolean true if the object is an instance

isAssignableFrom

public static boolean isAssignableFrom(Class cls)
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. Example:

if (klass1.isAssignableFrom(klass2)) {
}

Parameters:
cls - the Class object to be checked, such as zk.Widget.
Returns:
boolean true if assignable


Copyright © 2005-2011 Potix Corporation. All Rights Reserved. SourceForge.net Logo