Defining own classes
qooxdoo comes with it’s own implementation of namespaces and inheritance. If you use the qooxdoo framework inheritance is easier to use than it is normally the case with plain JavaScript.
Creating a simple new class
qx.OO.defineClass("my.ns.ClassName");
This will define a static class my.ns.ClassName. If you use the qooxdoo build system , this class should be defined in the my/ns subfolder of your source directory and should have the filename ClassName.js. qx.OO.defineClass automatically creates the missing namespace parts. You can also store a hash map like object inside a namespaces. This is comparable to a static class which directly gets some properties and functions:
qx.OO.defineClass("my.ns.ClassName", { key : value, id : function() {} });
As you can see, you can simply add another argument to directly define the object which should be stored under the given namespace.
With both methods the new class is available under the alias qx.Class afterwards (this is just true until you define the next class). You can attach as many functions and properties to the class itself afterwards e.g.:
qx.Class._value = 23; qx.Class.getValue = function() { return my.ns.ClassName._value; }
qx.Class is not valid inside the function body since at the time the function body is evaluated qx.Class is no longer valid. This is why the example code uses the fully qualified class name.
Inherit from an existing class
To inherit from another already existing class, you must change the parameters as follows:
qx.OO.defineClass("my.ns.ClassName", my.ns.SuperClass, function() { my.ns.SuperClass.call(this); });
The second parameter of qx.OO.defineClass is the constructor of the super class. The third parameter is the constructor method of the new class. Inside the constructor you must also execute the constructor of the superClass.
Using this code qx.Class is also available. Another variable which is available using this method is qx.Proto. qx.Proto is an alias to my.ns.ClassName.prototype, just a bit shorter. You can attach functions and values there to make them available to each instance of this class.
