-
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathindex.js
More file actions
29 lines (25 loc) · 760 Bytes
/
index.js
File metadata and controls
29 lines (25 loc) · 760 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
/**
* Create a subclass that can be modified without affecting the super class.
*
* @template {{prototype: object, new (...args: any[]): any}} Class
* @param {Class} Super
* @return {Class}
*/
export function unherit(Super) {
const Of = class extends Super {}
// Clone values.
const proto = Of.prototype
/** @type {string} */
let key
// We specifically want to get *all* fields, not just own fields.
// eslint-disable-next-line guard-for-in
for (key in proto) {
/** @type {unknown} */
const value = proto[key]
if (value && typeof value === 'object') {
// @ts-expect-error: shallow clone arrays or other values.
proto[key] = 'concat' in value ? value.concat() : Object.assign({}, value)
}
}
return Of
}