import { mixin } from "https://deno.land/x/ayonli_jsext@v0.9.72/workerd/index.ts";
Creates a class that combines all methods from the given base class and mixin classes.
Examples
Example 1
Example 1
import mixin from "@ayonli/jsext/mixin";
import { isSubclassOf } from "@ayonli/jsext/class";
class Log {
log(text: string) {
console.log(text);
}
}
class View {
display(data: Record<string, any>[]) {
console.table(data);
}
}
class Controller extends mixin(View, Log) {
constructor(readonly topic: string) {
super();
}
}
const ctrl = new Controller("foo");
ctrl.log("something is happening");
ctrl.display([{ topic: ctrl.topic, content: "something is happening" }]);
console.assert(isSubclassOf(Controller, View));
console.assert(!isSubclassOf(Controller, Log));
Type Parameters
T extends Constructor<any>
Parameters
base: T
...mixins: [X in keyof M]: Constructor<M[X]>
Returns
T & Constructor<UnionToIntersection<FlatArray<M, 1>>>
Type Parameters
T extends Constructor<any>
Returns
T & Constructor<UnionToIntersection<FlatArray<M, 1>>>