ES6 classes inherit from each other. So when instance.constructor
refers to the Child
, then you can use Object.getPrototypeOf(instance.constructor)
to get the Parent
, and then access .name
:
Object.getPrototypeOf(instance.constructor).name // == "Parent"
Of course, full ES6 compliance and non-minified code are necessary for this to work. You should never rely on function names in code.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…