First, we'll create a class called XObject to serve as the base class for all of the objects created using our framework. It will have only one method which calls the chain of constructors. Here is the prototype for the XObject class. Hover over an area to see a comment explaining the code.
01: function XObject() {}
02: XObject.prototype = {
03: constructors: [],
04: constructor: XObject,
05: init: function(args) {06: var constructors = this.constructor.prototype.constructors;
07: for ( var i = 0; i < constructors.length; ++i ) {
08: constructors[i].apply(this, args);
09: }10: }
11: }
The init method expects our framework to create an array of constructors, with element 0 referring to the constructor for the most distant ancestor. The real constructor will call XObject's init method which calls each of the psuedo-constructors.
Next we will describe how the real constructor for a class is created.