justinfagnani / mixwith.js

A mixin library for ES6

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Decorator syntax

trusktr opened this issue · comments

Might be nice to allow decorator syntax, so that instead of

class Foo extends mix(SuperClass).with(Foo, Bar) {}

we can

@with(Foo, Bar)
class Foo extends SuperClass {}

But I like better

@Foo @Bar
class Foo extends SuperClass {}

Are either of those decorator forms possible? Can we modify what the class extends (i.e. at first it extends SuperClass, but needs the foo and bar prototypes injected)? Would that be okay to do?

I think decorator syntax obscures what's actually going on with subclass factories - the key point is that they produce a new superclass for your class.

Decorators also happen at the wrong point: they receive the class already directly extending superclass, and then have to patch themselves into the prototype chain. They won't work with super or constructors either.