This is a static class library.
No, it is not. As is said twice before now, there are no classes. So there
are also no static classes.
TDescent.inheritsFrom(TBase);
Function.prototype.inheritsFrom = function(parentClass) {
this.prototype = new parentClass;
this.prototype.constructor = this;
this.prototype.__parentClass = parentClass;
return this;
}
I use a similar pattern but there is still no class. If TDescent() was used
as a constructor (with `new') an object would be created that inherits from
another object (the object TDescent.prototype refers to) through its
prototype chain, not from a class. And the other object again inherits from
yet another next object in its prototype chain, which supposedly inherits
from the object that Object.prototype refers to. (There you have the
fundamental difference between class-based and prototype-based inheritance.)
With your code, you are setting up the following prototype chain:
new TDescent() ---> new TBase() ---> ... ---> Object.prototype
When it should have been
new TDescent() ---> TBase.prototype ---> ... ---> Object.prototype
That is, with the current pattern TDescent objects inherit from a newly
created TBase object (not only with the properties they inherit from their
prototype, TBase.prototype, but with any modifications made to them in the
TBase() constructor). This can have undesired side-effects:
function TBase(foo)
{
if (!foo) this.bar = 42;
}
TBase.prototype = {
constructor: TBase
};
Now, since you essentially use
TDescent.prototype = new TBase();
all objects created with the constructor `TDescent', like
var o = new TDescent();
would have the `bar' property although it is not defined in TBase's
prototype object.
Hence Lasse's correctly recommending (again) to "clone" the prototype object
instead, IOW inserting a dummy object with no additional properties in the
prototype chain that has TBase.prototype as its prototype:
new TDescent() --> new Cloner() --> TBase.prototype --> ...
--> Object.prototype
For inheritance, I use
function TDescent(/*args*/) {
TBase.call(this, /*args*/);
//...
}
This is a constructor for an object in which another constructor is called.
No classes here.
I want to make some nice class diagrams for my thesis. aptana is an
excellent web-app editor.
The quality of Aptana is not under discussion here. The languages you are
writing your code in (ECMAScript Ed. 3 implementations) simply do not use or
provide class-based inheritance. You can emulate that to a certain degree,
but it will never be the same. A simple example:
var o = new TDescent();
o.answer = 42;
Now `o' has a property named `answer' although you would misguidedly
probably say it is an "instance of the class TDescent".
<
http://javascript.crockford.com/inheritance.html>
PointedEars