OverviewSingleDeprecated

jsx3.lang

class Class

Object
->jsx3.lang.Object
  ->jsx3.lang.Class

class Class
extends jsx3.lang.Object
JavaScript class that allows introspection of the JSX class hierarchy.

You may obtain an instance of jsx3.lang.Class in one of the following ways: This class is also used for defining classes. Use one of defineClass and defineInterface to define a class in the JSX class hierarchy. Note that any class defined in the package jsx3.lang is aliased into the jsx3 package. Therefore jsx3.lang.Object may also be referenced as jsx3.Object.

The following are class nomenclature definitions using jsx3.lang.Object as an example:

The following is an example of how to define a new class called Example in package eg:
jsx3.lang.Class.defineClass(
  "eg.Example",                   // the full name of the class to create
  eg.Base,                        // the class extends eg.Base
  [eg.Comparable, eg.Testable],   // the class implements interfaces eg.Comparable and eg.Testable
  function(Example) {             // name the argument of this function "Example"
    
    // every class must define an init method since it is called automatically by the constructor
    Example.prototype.init = function(arg1) {
      this.arg1 = arg1;
    };
    // define an instance method like this:
    Example.prototype.instanceMethod = function() {
      ...
    };
    // define an abstract method like this:
    Example.prototype.abstractMethod = jsx3.Method.newAbstract();
    // define a static method like this:
    Example.staticMethod = function() {
      ...
    };
    // define a static field like this:
    Example.STATIC_FIELD = "...";
    // define an instance field like this:
    Example.prototype.instanceField = "...";
  }
);

Since:

3.1

See Also:

jsx3.lang.Object, jsx3.lang.Method, jsx3.lang.Package

Method Summary
void
addMethodMixin(strMethod : String, objClass : jsx3.lang.Class, strMixin : String)
Registers a mixin class-method pair for the strMethod instance method of this class.
jsx3.lang.Object
bless(obj : Object)
Creates a new instance of this class and populates its properties with the properties of the obj parameter.
static void
defineClass(strName : String, objExtends : Function | jsx3.lang.Class, arrImplements : Array<jsx3.lang.Class | Function | String>, fctBody : Function)
Defines a new class in the JSX hierarchy.
static void
defineInterface(strName : String, objExtends : Function | jsx3.lang.Class, fctBody : Function)
Defines a new interface in the JSX hierarchy.
static jsx3.lang.Class
forName(strName : String)
Retrieve an instance of jsx3.Class for a fully-qualified class name.
Array<jsx3.lang.Class>
Returns an array of all the classes defined in this class.
Function
Returns the constructor function of this class.
jsx3.lang.Method
getGetter(strProp : String)
Returns the accessor (getter) method of this class's bean property strProp.
Array<jsx3.lang.Class>
Returns the array of classes and interfaces that this class inherits from, ordered by precedence from highest to lowest.
Array<String>
Returns the array of instance fields defined for this class.
jsx3.lang.Method
getInstanceMethod(strMethodName : String)
Returns the instance method defined in this class with name strMethodName.
Array<jsx3.lang.Method>
Returns the array of instance methods defined for this class.
Array<jsx3.lang.Class>
Returns the array of interfaces that this class was defined to implement.
String
Returns the fully-qualified name of this class.
jsx3.lang.Package
Returns the package of this class.
String
Returns the package name of this class, e.g.
jsx3.lang.Method
getSetter(strProp : String)
Returns the mutator (setter) method of this class's bean property strProp.
Array<String>
Returns the array of static fields defined for this class.
jsx3.lang.Method
getStaticMethod(strMethodName : String)
Returns the static method defined in this class with name strMethodName.
Array<jsx3.lang.Method>
Returns the array of static methods defined for this class.
jsx3.lang.Class
Returns the super class of this class.
boolean
Determines whether this class is the same as or is a superclass or superinterface of parameter objClass.
boolean
Determines whether an object is an instance of this class.
boolean
Returns whether this class was defined as an interface.
void
mixin(obj : Object, bNoClobber : boolean, arrNames : Array<String>)
Copies all the instance methods in this class into an instance (of another class).
jsx3.lang.Object
newInnerClass(arg : Object...)
Creates a new instance of this class so that it can be used to create a java-style inner class extending this class.
Object
newInstance(arg : Object...)
Creates a new instance of this class by invoking the class constructor.
String
Methods Inherited From jsx3.lang.Object
clone, equals, eval, getClass, getInstanceOf, getInstanceOfClass, getInstanceOfPackage, instanceOf, isInstanceOf, isSubclassOf, jsxmix, jsxsuper, jsxsupermix, setInstanceOf
Method Detail

addMethodMixin

void addMethodMixin(strMethod : String, objClass : jsx3.lang.Class, strMixin : String)
Registers a mixin class-method pair for the strMethod instance method of this class. This is a mechanism for allowing mixin style interfaces to inject behavior into methods while remaining compatible with method chaining via jsxsuper().

When this.jsxmix() is called from within an instance method, all registered mixin pairs are consulted. For each pair, if this is an instance of the class, then the method is called.

Parameters:

strMethodthe name of the method of this class to which to add the mixin.
objClassthe class for which
strMixin

Since:

3.5

See Also:

jsx3.lang.Object.jsxmix(), jsx3.lang.Object.jsxsuper()

bless

jsx3.lang.Object bless(obj : Object)
Creates a new instance of this class and populates its properties with the properties of the obj parameter. Does not call init() when instantiating the class.

Parameters:

objOptional parameter. If provided, this method will copy all the properties of obj into the newly created object.

Throws:

{jsx3.lang.Exception}if called on an instance of jsx3.lang.Class that represents an interface

Returns:

a new instance of this class 

defineClass

static void defineClass(strName : String, objExtends : Function | jsx3.lang.Class, arrImplements : Array<jsx3.lang.Class | Function | String>, fctBody : Function)
Defines a new class in the JSX hierarchy. After executing this method, an instance of jsx3.lang.Class representing the new class will be available for introspection.

Parameters:

strNamethe full name of the class to create, including the package prefix
objExtendsthe super class of the class to create; either the class constructor or the jsx3.Class instance itself. If no super class is provided, jsx3.Object will be used. May be null. If provided and representing an introspectable class, must be a class rather than an interface.
arrImplementsthe array of interfaces that the class to create will implement. Each item in the array may be either a class constructor, an instance of jsx3.Class, or a string but must represent an interface (a class created with defineInterface). May also be null or empty.
fctBodya function that defines the body of the class. This function takes two arguments, the constructor of the newly created interface, and its prototype. See class summary for more information.

defineInterface

static void defineInterface(strName : String, objExtends : Function | jsx3.lang.Class, fctBody : Function)
Defines a new interface in the JSX hierarchy. After executing this method, an instance of jsx3.lang.Class representing the new interface will be available for introspection.

Parameters:

strNamethe full name of the interface to create, including the package prefix
objExtendsthe super interface of the interface to create; either the class constructor or the jsx3.Class instance itself. If no super interface is provided, Object will be used. May be null. If provided and representing an introspectable class, must be an interface rather than a class.
fctBodya function that defines the body of the interface. This function takes two arguments, the constructor of the newly created interface, and its prototype. See class summary for more information.

forName

static jsx3.lang.Class forName(strName : String)
Retrieve an instance of jsx3.Class for a fully-qualified class name. This method will also return aliased classes such as jsx3.Object. Thus the name of the class returned by this method may not always equal the value of the strName parameter.

Parameters:

strNamethe fully-qualified (including package prefix) class name

Returns:

 

getClasses

Array<jsx3.lang.Class> getClasses()
Returns an array of all the classes defined in this class. This method returns the JSX equivalent of Java's public static inner classes.

To be returned by this method, a static inner class should be defined after the containing class is defined, like this:
jsx3.Class.defineClass("eg.ContainingClass", null, null, function(){});
jsx3.Class.defineClass("eg.ContainingClass.InnerClass", null, null, function(){});

Returns:

 

getConstructor

Function getConstructor()
Returns the constructor function of this class.

Returns:

 

getGetter

jsx3.lang.Method getGetter(strProp : String)
Returns the accessor (getter) method of this class's bean property strProp. Searches this class and the classes that it inherits method from for an instance method named "getStrProp" or "isStrProp" using the strProp parameter with the first letter made uppercase.

Parameters:

strPropthe name of the bean property whose getter to return

Returns:

the method or null if none found  

getInheritance

Array<jsx3.lang.Class> getInheritance()
Returns the array of classes and interfaces that this class inherits from, ordered by precedence from highest to lowest. This is the same order the defines where an inherited method will come from.

The order is:
  1. this class (not included in the returned array of this method)
  2. the interfaces that this class implements in the order that they were passed to the defineClass() function
  3. the superclass of this class ... recursively

Returns:

an array of jsx3.Class instances  

getInstanceFieldNames

Array<String> getInstanceFieldNames()
Returns the array of instance fields defined for this class.

Returns:

an array of String instances  

getInstanceMethod

jsx3.lang.Method getInstanceMethod(strMethodName : String)
Returns the instance method defined in this class with name strMethodName.

Parameters:

strMethodNamethe name of the method to find

Returns:

the method or null if none found matching strMethodName  

getInstanceMethods

Array<jsx3.lang.Method> getInstanceMethods()
Returns the array of instance methods defined for this class.

Returns:

an array of jsx3.lang.Method instances  

getInterfaces

Array<jsx3.lang.Class> getInterfaces()
Returns the array of interfaces that this class was defined to implement. This method does not return the interfaces that this class implements by way of its superclass.

Returns:

an array of jsx3.Class instances  

getName

String getName()
Returns the fully-qualified name of this class.

Returns:

 

getPackage

jsx3.lang.Package getPackage()
Returns the package of this class. This may be null if the namespace that this class was defined in was never initialized with jsx3.lang.Package.definePackage.

Returns:

 

getPackageName

String getPackageName()
Returns the package name of this class, e.g. jsx3.lang. If the package containing this class has been defined, then this method returns the name of the package. Otherwise, it returns the fully-qualified name of this class less the final token.

Returns:

 

getSetter

jsx3.lang.Method getSetter(strProp : String)
Returns the mutator (setter) method of this class's bean property strProp. Searches this class and the classes that it inherits method from for an instance method named "setStrProp" using the strProp parameter with the first letter made uppercase.

Parameters:

strPropthe name of the bean property whose setter to return

Returns:

the method or null if none found  

getStaticFieldNames

Array<String> getStaticFieldNames()
Returns the array of static fields defined for this class.

Returns:

an array of String instances  

getStaticMethod

jsx3.lang.Method getStaticMethod(strMethodName : String)
Returns the static method defined in this class with name strMethodName.

Parameters:

strMethodNamethe name of the method to find

Returns:

the method or null if none found matching strMethodName  

getStaticMethods

Array<jsx3.lang.Method> getStaticMethods()
Returns the array of static methods defined for this class.

Returns:

an array of jsx3.lang.Method instances  

getSuperClass

jsx3.lang.Class getSuperClass()
Returns the super class of this class. This will be null for an interface without a super interface or jsx3.lang.Object.

Returns:

null if no super class is defined  

isAssignableFrom

boolean isAssignableFrom(objClass : jsx3.lang.Class)
Determines whether this class is the same as or is a superclass or superinterface of parameter objClass.

Parameters:

objClassthe class to test

Returns:

 

isInstance

boolean isInstance(obj : Object)
Determines whether an object is an instance of this class.

Parameters:

objthe object to test

Throws:

{Error}if obj is null.

Returns:

 

isInterface

boolean isInterface()
Returns whether this class was defined as an interface.

Returns:

 

mixin

void mixin(obj : Object, bNoClobber : boolean, arrNames : Array<String>)
Copies all the instance methods in this class into an instance (of another class).

Parameters:

objthe target of the method transfer
bNoClobberif true, then do not transfer any methods already existing in obj
arrNames

newInnerClass

jsx3.lang.Object newInnerClass(arg : Object...)
Creates a new instance of this class so that it can be used to create a java-style inner class extending this class. This method will instantiate an interface or a class, in which case the init() method will be called. In this way you can accomplish the following:
var aClass = eg.Testable.jsxclass;       // get jsx3.lang.Class instance
var innerClass = aClass.newInnerClass(); // create inner class instance
innerClass.test = function() {};         // implement the eg.Testable interface
innerClass instanceof eg.Testable;       // evaluates to true

Parameters:

argarguments to pass to the constructor, supports up to 10 arguments

Returns:

a new instance of this class  

newInstance

Object newInstance(arg : Object...)
Creates a new instance of this class by invoking the class constructor. This is equivalent to calling new() on this class's constructor function and will call the class's init() method.

Parameters:

argthe variable number of arguments to send to the constructor

Returns:

 

toString

String toString()

Returns:

 

Overrides:

toString in jsx3.lang.Object