Mixins Available since v0.8
@aedart/support/mixins
offers an adaptation of Justin Fagnani'smixwith.js
package (originally licensed under Apache License 2.0).
import { mix, Mixin } from "@aedart/support/mixins";
// Define mixin
const NameMixin = Mixin((superclass) => class extends superclass {
#name;
set name(value) {
this.#name = value;
}
get name() {
return this.#name;
}
});
// Apply mixin...
class Item extends mix().with(
NameMixin
) {
// ...not shown...
}
// ...Later in your application
const item = new Item();
item.name = 'My Item';
console.log(item.name); // My Item
See also Concerns as an alternative.