-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathextend.js
More file actions
18 lines (15 loc) · 571 Bytes
/
extend.js
File metadata and controls
18 lines (15 loc) · 571 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
/**
* @copyright 2023 Chris Zuber <admin@kernvalley.us>
*/
export function extend(base = class EmptyClass {}, ...classes) {
class CompositeClass extends base {}
for (const parent of classes.reverse()) {
const staticProps = Object.getOwnPropertyDescriptors(parent);
const instanceProps = Object.getOwnPropertyDescriptors(parent.prototype);
delete staticProps.prototype;
delete instanceProps.constructor;
Object.defineProperties(CompositeClass, staticProps);
Object.defineProperties(CompositeClass.prototype, instanceProps);
}
return CompositeClass;
}