First commit
This commit is contained in:
25
framework/unify/multiExtend.js
Normal file
25
framework/unify/multiExtend.js
Normal file
@@ -0,0 +1,25 @@
|
||||
|
||||
|
||||
export default (baseClass, ...mixins) => {
|
||||
class base extends baseClass {
|
||||
constructor (...args) {
|
||||
super(...args);
|
||||
mixins.forEach((mixin) => {
|
||||
copyProps(this,(new mixin));
|
||||
});
|
||||
}
|
||||
}
|
||||
let copyProps = (target, source) => { // this function copies all properties and symbols, filtering out some special ones
|
||||
Object.getOwnPropertyNames(source)
|
||||
.concat(Object.getOwnPropertySymbols(source))
|
||||
.forEach((prop) => {
|
||||
if (!prop.match(/^(?:constructor|prototype|arguments|caller|name|bind|call|apply|toString|length)$/))
|
||||
Object.defineProperty(target, prop, Object.getOwnPropertyDescriptor(source, prop));
|
||||
})
|
||||
}
|
||||
mixins.forEach((mixin) => { // outside contructor() to allow aggregation(A,B,C).staticFunction() to be called etc.
|
||||
copyProps(base.prototype, mixin.prototype);
|
||||
copyProps(base, mixin);
|
||||
});
|
||||
return base;
|
||||
}
|
||||
Reference in New Issue
Block a user