So the answer to "How do I do mixins in JS?" is crickets? It's seems like such an obvious pattern in so many cases… and yet…
-
-
I think we could use a maximally minimal mixins proposal that just desugars to this. It's be a boon for static analysis.
-
Yeah, that would be awesome and consistent with classes.
-
This is more or less my preferred solution. There's a lot of class features in flight right now, but this feels like a good next step.
End of conversation
New conversation -
-
-
Yes, we talked about this approach at TC39 at some point and it pretty much put mix-in discussions on the shelf. Basically ES6+ already supports mix-ins. This is the only mix-im pattern I ever use or show.
-
Those require a superclass, though, no? And/or some weirdness around having to call a phantom super constructor method.
-
function MyMixIn(Super=Object) { … }
-
That inherits unwanted stuff from Object though. It'd be nice if we could change the semantics of extending null so that it made a base class, and if base classes could call super() without an error.
-
Since I don't think you can't extend null in practice (no valid super ctor to call), maybe that's still possible.
-
class extends null {} works. the super constructor is Function.prototype
-
You can make the declaration, but new throws: class C extends null {} new C(); > Uncaught TypeError: Super constructor null of C is not a constructor
-
It not suppose to, see steps 5.b and 6.e.ii of https://tc39.github.io/ecma262/#sec-runtime-semantics-classdefinitionevaluation … But it looks like a spec. bug in step 10.ais cause the wrong default constructor go be generated. cc/
@bterlson@littledan - 8 more replies
New conversation -
-
-
I used mixins for combining many packages for es-git, and I'm fairly happy with the result. There are some weird corners, but it mostly works, even with typescript https://github.com/es-git/es-git/blob/master/readme.md …
Thanks. Twitter will use this to make your timeline better. UndoUndo
-
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.