astro-ghostcms/.pnpm-store/v3/files/40/70240b4347c57a82191f9b0edd0...

30 lines
760 B
Plaintext
Raw Normal View History

2024-02-14 14:10:47 +00:00
/**
* 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
}