mirror of
https://github.com/tiramisulabs/seyfert.git
synced 2025-07-03 05:26:07 +00:00
fix(mixer): toString
This commit is contained in:
parent
633b19c382
commit
9b765c1fc5
@ -22,6 +22,7 @@ function getDescriptors(c: TypeClass) {
|
|||||||
* @returns The mixed class.
|
* @returns The mixed class.
|
||||||
*/
|
*/
|
||||||
export function Mixin<T, C extends TypeClass[]>(...args: C): C[number] & T {
|
export function Mixin<T, C extends TypeClass[]>(...args: C): C[number] & T {
|
||||||
|
const ignoreOverwriteToString = Object.keys(Object.getOwnPropertyDescriptors(args[0].prototype)).includes('toString');
|
||||||
function MixedClass(...constructorArgs: any[]) {
|
function MixedClass(...constructorArgs: any[]) {
|
||||||
for (const i of args) {
|
for (const i of args) {
|
||||||
const descriptors = getDescriptors(i);
|
const descriptors = getDescriptors(i);
|
||||||
@ -31,9 +32,13 @@ export function Mixin<T, C extends TypeClass[]>(...args: C): C[number] & T {
|
|||||||
|
|
||||||
for (const descriptorK in j) {
|
for (const descriptorK in j) {
|
||||||
if (descriptorK === 'constructor') continue;
|
if (descriptorK === 'constructor') continue;
|
||||||
if (descriptorK in MixedClass.prototype) continue;
|
if (descriptorK in MixedClass.prototype && descriptorK !== 'toString') continue;
|
||||||
const descriptor = j[descriptorK];
|
const descriptor = j[descriptorK];
|
||||||
if (descriptor.value) {
|
if (descriptor.value) {
|
||||||
|
if (descriptorK === 'toString' && ignoreOverwriteToString) {
|
||||||
|
MixedClass.prototype[descriptorK] = args[0].prototype.toString;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
MixedClass.prototype[descriptorK] = descriptor.value;
|
MixedClass.prototype[descriptorK] = descriptor.value;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user