Skip to content

Support C3 #2

@mercmobily

Description

@mercmobily

Right now, SimpleDeclare seems to do hierarchy linearisation the way the old Python 2.2 used to. There is nothing wrong with it, but the "good" way of doing it seems to be C3 Method Resolution Order (C3MRO).

Here is a good document that explains it all. The only other library that does C3MRO I know about is Dojo's declare.

The relevant code in SimpleDeclare is the part where it goes:

        // NOW:
        // Go through every __proto__ of every derivative class, and augment
        // MixedClass by inheriting from A COPY OF each one of them.

The first cycle gets the full list of constructors:

          // Get the prototype list, in the right order
          // (the reversed discovery order)
          // The result will be placed in `subList`
          var subList = [];    
          proto = SuperCtorList[ i ].prototype;
          while( proto ){
            if( proto.constructor !== Object ) subList.push( proto );
            proto = Object.getPrototypeOf( proto );
          }
          subList = subList.reverse();

Then, the real funk begins... the result must be MixedClass, a constructor with the correctly linearised constructors.

Anybody feeling brave? I would love to see this in SimpleDeclare, but have no urgency for it -- and have already spent MONSTROUS amounts of time on it. It's fully tested (more than 100 tests, if you think of more let me know).

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions