JavaScript: console log shows parent class name instead of derived class name

74 Views Asked by At

If I declare a non-derived class, the console log shows the class name of instances:

class A {constructor(){}}
new A();
-> A {}

However, when I declare a derived class, the console log shows the parent class name instead:

class B extends EventTarget {constructor(){super();}}
new B();
-> EventTarget {}

This seems to happen in every browser I tried (Chrome, Firefox, very old, very new).

Can the derived class be declared in a way that the class name appears in the console log?

0

There are 0 best solutions below