To define class in es6, you can do this
class A {
x = 1;
y = 2;
z = 3;
mx () { // ... }
my () { // ... }
mz () { // ... }
}
When there are more and more A class attribute methods, it is found that the entire file has a large amount of code. Can some properties and methods be divided into a single file (for example, x and mx are divided into one x.js file, y and my are divided into one y.js file...)
If you use extends, you will find a problem. Properties cannot be shared, and neither can methods.
Can we combine (x.js / y.js / ...) into A when defining class A?
阿神2017-06-28 09:30:59
Mixin
Mode
In short, it is to merge the prototype
attributes of several classes, and the last big class can inherit this merged class.
Ruan Yifeng’s ES6 tutorial has a sample program, you can refer to: Mixin-pattern implementation