proposal-mixins
proposal-mixins copied to clipboard
Constructor?
I have concerns about constructor
s in mixins. Allowing declaring constructor in mixins means allowing access to super since it's a must to call super
in constructor, which would lead to origin class reference leakage.
As I understand mixins, they adds own properties and methods and encapsulate logic acting like a plain JS object. But allowing a constructor
somewhat equals them to classes, which is not that simple.
For initiating logic I would expect to have a dedicated keyword like init
mixin Network {
online = false
connect() {...}
disconnect() {...}
init {
this.connect()
}
}
In case of mixin extension, the extensions would just add up to this
as they are a part of origin mixin since there could be multiple mixin extensions.
mixin Events {
listeners = new Set
dispatch() {...}
on() {...}
}
mixin Socket extends Network {
init {
this.dispatch(...) // no access to `super` in mixins.
}
}