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

Call "super" in class hierarchy. #1

Open
shaunc opened this issue Feb 27, 2015 · 1 comment
Open

Call "super" in class hierarchy. #1

shaunc opened this issue Feb 27, 2015 · 1 comment

Comments

@shaunc
Copy link

shaunc commented Feb 27, 2015

I understand that the default "super" from coffeescript access super in the Mixin's class heirarchy. However, it would be great if there were some way to use a mixin to access function overridden in the heirarchy it is mixed into. I have found the following workaround works if there is no other function in the Mixin heirarchy:

class Mixin
  foo: (bar)->
    @constructor.__super__.constructor.__super__.foo(bar)

(Going up 1 step gets you back to the same "foo" you started with.) This would suggest that you could provide some sugar for this... perhaps callable as (e.g.):

  foo: ()->
    @classSuper('foo', bar)
@yangmillstheory
Copy link

@shaunc I don't the mixin should know anything about the classes it's mixed into, like whether or not a superclass implementation exists (which means knowing where it is in the mixed-in hierarchy).

I think that the best way to accomplish what you're proposing is to let the mixing class call super (it's the right place, since it knows its own hierarchy) when overriding a mixin method, but to keep a reference to the mixin method.

In this way the mixin method wouldn't be invoked with super - which seems wrong, since mixins don't define an "is-a" relationship, but rather a "behaves-like-a" relationship). The mixin method could be invoked using a name-mangled reference, or automatically - the mixing class could inject custom behavior by using hooks provided by the mixin.

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