Skip to content

Multiple inheritance? Mixins? #452

@TrevorBurnham

Description

@TrevorBurnham

I'm loving the extends keyword, but in the course of developing a complex project, I really wish I could give a class functionality from multiple sources. Obviously I could do this by extending the prototype manually, but it feels like a hack to mix the extends syntax with JavaScript-style prototype manipulation.

For my purposes, it would be great to be able to say

class A extends Foo, Bar

but I realize that multiple inheritance is a huge headache, so Ruby-style mixins or Scala-style traits would probably be a better solution. The Scala syntax would be especially nice for CoffeeScript:

class A extends Foo with Bar

Obviously with is already a keyword, but its meaning in this syntax is unambiguous.

Of course, this is something that a standard library could do, but it would be much clearer to have something like the above syntax rather than something like

class A extends foo
   # properties...

lib.mixin A, bar

What does everyone else think?

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions