31 lines
No EOL
907 B
JavaScript
31 lines
No EOL
907 B
JavaScript
//#region src/_inherit.ts
|
|
function lazyInherit(target, source, sourceKey) {
|
|
for (const key of [...Object.getOwnPropertyNames(source), ...Object.getOwnPropertySymbols(source)]) {
|
|
if (key === "constructor") continue;
|
|
const targetDesc = Object.getOwnPropertyDescriptor(target, key);
|
|
const desc = Object.getOwnPropertyDescriptor(source, key);
|
|
let modified = false;
|
|
if (desc.get) {
|
|
modified = true;
|
|
desc.get = targetDesc?.get || function() {
|
|
return this[sourceKey][key];
|
|
};
|
|
}
|
|
if (desc.set) {
|
|
modified = true;
|
|
desc.set = targetDesc?.set || function(value) {
|
|
this[sourceKey][key] = value;
|
|
};
|
|
}
|
|
if (!targetDesc?.value && typeof desc.value === "function") {
|
|
modified = true;
|
|
desc.value = function(...args) {
|
|
return this[sourceKey][key](...args);
|
|
};
|
|
}
|
|
if (modified) Object.defineProperty(target, key, desc);
|
|
}
|
|
}
|
|
|
|
//#endregion
|
|
export { lazyInherit as t }; |