Is it possible to get an object's class/type name at runtime using TypeScript?
class MyClass{} var instance = new MyClass(); console.log(instance.????); // Should output "MyClass"
You have to use this snippet code for object: yourObject. getClass(). getSimpleName();
If you have a JavaSW object, you can obtain it's class object by calling getClass() on the object. To determine a String representation of the name of the class, you can call getName() on the class.
Java provides three different ways to find the type of an object at runtime like instanceof keyword, getClass(), and isInstance() method of java. lang. Class.
To get the class name of an instance in Python: Use the type() function and __name__ to get the type or class of the Object/Instance. Using the combination of the __class__ and __name__ to get the type or class of the Object/Instance.
class MyClass {} const instance = new MyClass(); console.log(instance.constructor.name); // MyClass console.log(MyClass.name); // MyClass
However: beware that the name will likely be different when using minified code.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With