jsx3.lang.Class.
jsx3.lang.Object defines the method
getClass(), which returns an instance of jsx3.lang.Class. This method is useful for
testing whether an object is an instance of exactly (not a superclass of) a class.instanceof: obj instanceof jsx3.lang.Object. Note that the right hand argument of this
expression must be the constructor function of a class and not of an interface defined with
jsx3.Class.defineInterface()).instanceOf() defined in
jsx3.lang.Object. This method will check against all classes and interfaces but is probably slower
than the instanceof operator.
var doc = new jsx3.gui.Block();
doc.getClass().equals(jsx3.gui.Block.jsxclass); // true
doc.getClass().equals(jsx3.app.Model.jsxclass); // false, even though Block extends Model
doc instanceof jsx3.gui.Block; // true
doc instanceof jsx3.app.Model; // true
doc instanceof jsx3.util.EventDispatcher; // false, EventDispatcher is an interface
doc instanceof Object; // true, works on non-jsx3.Class class constructors
doc.instanceOf(jsx3.gui.Block); // true
doc.instanceOf(jsx3.app.Model.jsxclass); // true, accepts arguments of type jsx3.Class
doc.instanceOf('jsx3.lang.Object'); // true, accepts arguments of type String
doc.instanceOf(jsx3.util.EventDispatcher); // true, works on interfaces
doc.instanceOf(Object); // true, works on non-jsx3.Class class constructors
| Constructor Summary | |
|---|---|
| void | init() Instance initializer. |
| Method Summary | |
|---|---|
| jsx3.lang.Object | clone() Returns a shallow copy of this object. |
| boolean | Returns true if this object is equals to the obj parameter. |
| Object | Eval a string of code with a particular this and local variable stack context. |
| jsx3.lang.Class | getClass() Returns the class of this object. |
| String | Deprecated. use Object.getClass()
|
| String | Deprecated. use Object.getClass().getName() and parse out final token
|
| String | Deprecated. use Object.getClass().getPackageName()
|
| boolean | instanceOf(objClass : Function | jsx3.lang.Class | String) Determines whether this object is an instance of objClass, that is, whether
objClass is equal to or a superclass or superinterface of this object's class. |
| boolean | Deprecated. use instanceof or Object.instanceOf()
|
| boolean | isSubclassOf(strClassName : String) Deprecated. no direct replacement
|
| void | Invokes any method mixins registered with the method that calls jsxmix(). |
| protected Object | undefined | Calls the supermethod overridden by the method that calls jsxsuper(). |
| protected Object | undefined | jsxsupermix(arg : Object...) Like jsxsuper() but traverses up through all the interfaces implemented by this class and its super classes. |
| void | setInstanceOf(strInstanceOf : String) Deprecated. no direct replacement
|
| String | toString() |
| Constructor Detail |
|---|
| Method Detail |
|---|
obj parameter.Object.getClass().getName() and parse out final token
Object.getClass().getPackageName()
objClass, that is, whether
objClass is equal to or a superclass or superinterface of this object's class.objClass is a string that is not the name of a registered class
instanceof or Object.instanceOf()
jsxmix(). A method mixin is
only invoked if this object is an instance of the class registered with the mixin.
jsxmix() is useful when a method of a base or abstract class is designed to be overridden and
chained by a subclass and when interface(s) that the subclass implements need to "inject" behavior into the
method chain. For example:
jsx3.Class.defineClass("BaseClass", null, null, function(BaseClass) {
BaseClass.prototype.onEvent = function(objEvent) {
this.jsxmix(objEvent);
jsx3.log("Handling event " + objEvent + " in BaseClass.");
};
});
jsx3.Class.defineInterface("Mixin", null, function(Mixin) {
Mixin.prototype._onEvent = function(objEvent) {
jsx3.log("Handling event " + objEvent + " in Mixin.");
};
BaseClass.jsxclass.addMethodMixin("onEvent", Mixin.jsxclass, "_onEvent");
});
jsx3.Class.defineClass("SubClass", BaseClass, [Mixin], function(SubClass) {
SubClass.prototype.onEvent = function(objEvent) {
jsx3.log("Handling event " + objEvent + " in SubClass.");
this.jsxsuper(objEvent);
};
});
Subclass.prototype.init = function(a, b, c) {
this.jsxsuper(a, b); // calls the init() method in the superclass of Subclass
this.c = c;
};
jsx3.lang.Class.defineClass()/defineInterface(), or if no suitable super method exists
// imagine that the jsx3.Testable mixin interface defines a method test() that provides basic testing functionality
jsx3.Class.defineClass('eg.Test', null, [jsx3.Testable], function(Test){
Test.prototype.test = function() {
this.setUpTest(); // do something before running the test
this.jsxsupermix(); // calls test() in jsx3.Testable
this.tearDownTest(); // do something after running the test
};
});
jsx3.lang.Class.defineClass()/defineInterface(), or if no suitable super method exists