Ticket #73 (closed defect: fixed)

Opened 4 years ago

Last modified 2 years ago

change Widget system inheritence to prototypal mixin

Reported by: psowden Owned by: sjmiles
Priority: normal Milestone:
Component: General Version: 0.1
Severity: normal Keywords:
Cc:

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

type.html (25.2 kB) - added by morris_dojo73@… 3 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.

Change History

Changed 4 years ago by alex

  • milestone changed from 0.2release to 0.3release

Changed 3 years ago by morris_dojo73@…

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.

Changed 3 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.

Changed 3 years ago by alex

  • milestone changed from 0.3release to 0.4

moving to widget release

Changed 3 years ago by sjmiles

  • owner changed from alex to sjmiles

Changed 3 years ago by sjmiles

  • status changed from new to closed
  • resolution set to fixed

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.

Changed 2 years ago by anonymous

  • milestone deleted

Milestone 0.4 deleted

Note: See TracTickets for help on using tickets.