Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add mixins to the inherit call? #33

Open
samreid opened this issue Nov 21, 2017 · 4 comments
Open

Add mixins to the inherit call? #33

samreid opened this issue Nov 21, 2017 · 4 comments
Assignees

Comments

@samreid
Copy link
Member

samreid commented Nov 21, 2017

Would it simplify our inheritance system or make it easier to read/understand if mixins were specified in the inheritance call?

inherit(Object,[mixins],Type,{},{})

I considered this will working on phetsims/tandem#31

@jonathanolson
Copy link
Contributor

The order of parameters there would definitely complicate how inherit would detect things (or would be impossible).

And usually mixing in is a function call (with parameters potentially). Are you thinking we'd need to have, e.g.:

inherit( Object, [ new Poolable( { maxPoolSize: 100 } ) ], Type, {}, {} );

This seems like it would add complications.

@samreid
Copy link
Member Author

samreid commented Nov 21, 2017

It looks like it would be even more complicated if we have to supply arguments like

  Poolable.mixInto( Bounds2, {
    defaultFactory: function() { return Bounds2.NOTHING.copy(); },
    constructorDuplicateFactory: function( pool ) {
      return function( minX, minY, maxX, maxY ) {
        if ( pool.length ) {
          return pool.pop().setMinMax( minX, minY, maxX, maxY );
        }
        else {
          return new Bounds2( minX, minY, maxX, maxY );
        }
      };
    }
  } );

Or would those be "abstract" methods that get implemented in the prototype (in the first {} in the inherit call)?

@samreid samreid assigned jonathanolson and unassigned samreid Nov 21, 2017
@samreid
Copy link
Member Author

samreid commented Nov 27, 2017

I came across this mixin/inheritance library: https://github.com/rse/aggregation which uses this syntax (es6)

class Rectangle extends aggregation(Shape, Colored, ZCoord) {}

@samreid
Copy link
Member Author

samreid commented Nov 29, 2017

I also noticed ES6 provides mixin support: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants