Opened 14 years ago

Closed 13 years ago

Last modified 13 years ago

#73 closed defect (fixed)

change Widget system inheritence to prototypal mixin

Reported by: psowden Owned by: sjmiles
Priority: high Milestone:
Component: General Version: 0.1
Keywords: Cc:
Blocked By: Blocking:

Description

The inheritence chain for a widget should descend from Widget into the specific implementation like so:

Widget -> Menu -> DomMenu? -> HtmlMenu?

The render specific Widget classes (DomWidget?, HtmlWidget?...) will be defined as interfaces which get "mixed in" to the corresponding Dom*, Html*... object's prototypes.

This will hopefully allow us to:

  • have a single defined interitence chain
  • allow us to check for instances of both Widget and Menu
  • allow us to call superclass methods in our *Menu chain
  • still reap the benefits of abstracting to *Widget

Attachments (1)

type.html (25.2 KB) - added by morris_dojo73@… 14 years ago.
An example of a tidy way to do super() or base() using this.inherited(arguments); - there is a lot of other meta junk in there sorry, the key function is declared inherited : function... Discussed with Bill. Not sure if useful, but have a squiz! Cheers, Morris.

Download all attachments as: .zip

Change History (7)

comment:1 Changed 14 years ago by alex

Milestone: 0.2release0.3release

Changed 14 years ago by morris_dojo73@…

Attachment: type.html added

An example of a tidy way to do super() or base() using this.inherited(arguments); - there is a lot of other meta junk in there sorry, the key function is declared inherited : function... Discussed with Bill. Not sure if useful, but have a squiz! Cheers, Morris.

comment:2 Changed 14 years ago by morris_dojo73@…

Oh, the reason it is tidy is because it works using the prototype chain.

Trick 1: defining superProto on each method eg.

function someMethod() {};
someMethod.superProto = SuperClass.prototype;
someMethod.Meta$$functionName = 'someMethod';

Trick 2: calling the superclass (done more generically in inherited by getting caller function from args) - rolled out a call to super() looks like:

function someMethod() {
  // call super()
  arguments.callee.superProto[arguments.callee.Meta$$functionName].call(this);
}

Note - no references to classnames!

Using the inherited function declared in the attached file it looks like:

function someMethod() {
  // call super()
  this.inherited(arguments);
}

Or you could rewrite inherited(), and rename it to base (C++ style!) it looks like:

function someMethod() {
  // call super()
  base(this, arguments);
}

Caveats:

a) You need to define superProto on every method of the class - perhaps in extends() - this only occurs once when the class prototype is first constructed.

b) A function can only be used in one prototype. You cannot 'share' the same function between two prototypes i.e. you cannot go Class1.prototype.methodx = Class2.prototype.methody; (two references to same function). This is because the function object can only have one superProto attribute and one functionName attribute!

Anyway, thought it might be useful. Give me an email even if just to flame me!

Cheers, Morris.

comment:3 Changed 14 years ago by alex

Milestone: 0.3release0.4

moving to widget release

comment:4 Changed 14 years ago by sjmiles

Owner: changed from alex to sjmiles

comment:5 Changed 13 years ago by sjmiles

Resolution: fixed
Status: newclosed

I'm closing this tag because I believe we have settled on a widget inheritance structure now.

There are open questions wrt to what sort of OOP methods should be employed, but that is a separate question.

comment:6 Changed 13 years ago by (none)

Milestone: 0.4

Milestone 0.4 deleted

Note: See TracTickets for help on using tickets.