// mx components... // mx.core.UIObject UIObject = function() { trace("UIObject ctor called"); super(); }; UIObject.prototype = new MovieClip(); UIObject.prototype.name = "UIObject"; UIObject.prototype.hello = function() { return "Hello from UIObject"; }; trace(" UIObject.prototype.constructor is MovieClip ? " + (UIObject.prototype.constructor == MovieClip)); // mx.core.UIComponent UIComponent = function () { trace("UIComponent ctor called, super is "+super.name+" (calling it next)"); super(); }; trace(" making UIComponent derive from UIObject"); UIComponent.prototype = new UIObject(); UIComponent.prototype.hello = function() { return "Hello from UIComponent"; }; UIComponent.prototype.name = "UIComponent"; trace(" UIObject.prototype.constructor is UIObject ? " + (UIComponent.prototype.constructor == UIObject)); // mx.core.SimpleButton SimpleButton = function () { trace("SimpleButton ctor called, super.name is "+super.name+" (calling it next)"); trace(" super == UIComponent.prototype ? " + ( super == UIComponent.prototype) ); trace(" super == UIComponent.constructor ? " + ( super == UIComponent.constructor) ); trace(" super == UIComponent.__constructor__ ? " + ( super == UIComponent.__constructor__) ); trace(" super == UIObject.prototype ? " + ( super == UIObject.prototype) ); trace(" super == UIObject.constructor ? " + ( super == UIObject.constructor) ); trace(" super == UIObject.__constructor__ ? " + ( super == UIObject.__constructor__) ); trace(" super == SimpleButton.prototype ? " + ( super == SimpleButton.prototype) ); trace(" super == SimpleButton.constructor ? " + ( super == SimpleButton.constructor) ); trace(" super == SimpleButton.__constructor__ ? " + ( super == SimpleButton.__constructor__) ); trace(" typeof(super.hasOwnProperty) " + typeof(super.hasOwnProperty)); trace(" super.hasOwnProperty('name') ? " + super.hasOwnProperty('name')); trace(" typeof(super.prototype) ? " + typeof(super.prototype)); trace(" super.hasOwnProperty('constructor') ? " + super.hasOwnProperty('constructor')); trace(" super.constructor === UIComponent ? " + ( super.constructor === UIComponent ) ); trace(" super.constructor === UIObject ? " + ( super.constructor === UIObject ) ); trace(" super.hasOwnProperty('__constructor__') ? " + super.hasOwnProperty('__constructor__')); trace(" super.__constructor__ === UIComponent ? " + ( super.__constructor__ === UIComponent ) ); trace(" super.__constructor__ === UIObject ? " + ( super.__constructor__ === UIObject ) ); trace(" super.__proto__.hasOwnProperty('name') ? " + super.__proto__.hasOwnProperty('name') + " (" + super.__proto__.name+")" ); trace(" super.__proto__ === UIComponent.prototype ? " + ( super.__proto__ === UIComponent.prototype )); trace(" super.__proto__ === UIObject.prototype ? " + ( super.__proto__ === UIObject.prototype )); //UIComponent.prototype = new Object; // still UIComponent ctor (super()) will invoke UIObject when calling 'super' var a = super; a(); trace("Hello from super: "+super.hello()); UIComponent.prototype.hello = function() { return "overridden UIComponent.prototype.hello"; }; trace("HEllo from super after overriding UIComponent.hello: "+super.hello()); SimpleButton.constructor = UIObject; trace("Hello from super after changing SimpleButton.constructor to UIObject: "+super.hello()); SimpleButton.__constructor__ = UIObject; trace("Hello from super after changing SimpleButton.__constructor__ to UIObject: "+super.hello()); SimpleButton.prototype = new UIObject; trace("Hello from super after changing SimpleButton.prototype to UIObject.prototype: "+super.hello()); this.__constructor__ = UIObject; trace("Hello from super after changing this.__constructor__ to UIObject: "+super.hello()); this.constructor = UIObject; trace("Hello from super after changing this.constructor to UIObject: "+super.hello()); SimpleButton.__proto__ = UIObject.prototype; trace("Hello from super after changing SimpleButton.__proto__ to UIObject.prototype: "+super.hello()); UIComponent = function() { trace("Overridden UIComponent ctor"); }; super(); }; trace(" making SimpleButton derive from UIComponent"); SimpleButton.prototype = new UIComponent(); trace(" SimpleButton.prototype.constructor is UIComponent ? " + (SimpleButton.prototype.constructor == UIComponent)); trace(" instantiating SimpleButton"); b = new SimpleButton(); trace("-----"); UIComponent.prototype(); trace(" -- Conclusions -- super is a special object bound to a function/class. 1. Calling it fires the functin/class constructor. 2. Fetching it's members returns members of the function/class *prototype* object 3. References to the function/class prototype and constructor are stored at construction time, not queried at get_member or call time, as changing prototype or constructor doens't change the behaviour of calling super() or fetching its members. Note in particular that the prototype is not fetched from the constructor. ");