cup-mixin
v1.0.0
Published
Multiple inheritance in JavaScript
Maintainers
Readme
cup-mixin
This module enables multiple inheritance in JavaScript, supporting ES2020+ private fields, methods, static methods, and getters/setters.
Installation
npm i cup-mixinMotivation

Usage
Extend the Mixin class in your modules to enable multiple inheritance. Call the mixin() static method inside the descendant class (passing this) to dynamically apply module functionality at runtime.
import { Mixin } from 'node_modules/cup-mixin/index.js'First module
class A extends Mixin {
constructor() {
super()
}
aMethod() {
console.log('hello')
}
}Second module
class B extends Mixin {
constructor() {
super()
}
bMethod() {
console.log('world')
}
}Descendant class
class MyClass {
constructor() {
/* Multiple inheritance... */
A.mixin(this)
B.mixin(this)
/* Simple as this! */
}
}
const myClass = new MyClass()
myClass.aMethod() // 'hello'
myClass.bMethod() // 'world'Supported Inheritance Types
| Feature | Supported | |-------------------|-----------| | Public Methods | ✅ | | Private Methods | ✅ | | Public Variables | ✅ | | Private Variables | ✅ | | Getters | ✅ | | Setters | ✅ | | Static Methods | ✅ |
What does 'cup' stand for?
It's like cup noodles; quick and not fancy.
Tests
npm run test