© 2005 Goetz Heller
Table of Contents Classes Copyright Note backSince prior to JavaScript Version 2 - which as of today is not in common use - the language has only limited support for classes and no support for namespaces at all, there is no syntax to handle these constructs, e.g. there is no class inheritance comparable to other commonly used object oriented languages. Taking this into consideration, we need to follow some guidelines in order to get comparable results. Luckily, this does not impose to much burden on our shoulders. The hardest inconvenience is calling super class methods where we need to supply the complete superclass ID in combination with the use of the call() function. This could be simplified somehow if namespace shortcuts were added to the class definition. For the sake of clearity I left this out from the following recommendations. Note that there is no reason why you should not store multiple modules in one file - on the contrary, in a load-on-demand situation, this could speed up things because fewer connections to the server are needed. Compare this to downloading Java jar files.
var baseClass=core.getClassByID(full.Base.Class.Name.String);
var cls=function(){};
core.derive(cls, baseClass);
cls.prototype.initialize=function(arg0, arg1, ...) { ...};If derived from baseClass, and if baseClass has a member initialize(), add the statement
core.getClassByID(base.Class.Name.String).prototype.initialize.call(this, Arg0, Arg1, ...);to the method body.
cls.prototype.reset=function() { ...};If derived from class baseClass, and if base has a member reset(), add the statement
core.getClassByID(base.Class.Name.String).prototype.reset.call(this);to the method body.
core.installClass(cls);
try { eval(full.Class.Name.String); } catch(e) { // don't install twice // dependencies try { eval('core'); } catch(e) { throw new Error('full.Class.Name.String: class \'core\' not installed'); } // more dependency checks ... // module definitions go here ... } // end catch