Define a new Mixin
You can use the Mixin decorator to define a new mixin. Amongst other things, the decorator will enable support for instanceof checks. See instanceof Operator for additional information.
import { Mixin } from "@aedart/support/mixins";
export const RectangleMixin = Mixin((superclass) => class extends superclass {
length = 0
width = 0;
area() {
return this.length * this.width;
}
});
Constructor
If you need to perform initialisation logic in your mixins, then you can do so by implementing a class constructor. When doing so, it is important to invoke the parent constructor via super() and pass on eventual arguments.
import { Mixin } from "@aedart/support/mixins";
export const RectangleMixin = Mixin((superclass) => class extends superclass {
constructor(...args) {
super(...args); // Invoke parent constructor and pass on arugments!
// Perform your initialisaiton logic...
}
// ...remaining not shown...
});