You can use the name property of the object's constructor function to get the name of the class that is used to instantiated the object. Let's take a look an example:
<script>
class Rectangle {
// Class constructor
constructor(length, width) {
this.length = length;
this.width = width;
}
// Class method
getArea() {
return this.length * this.width;
}
}
var rectObj = new Rectangle(5, 10);
alert(rectObj.getArea()); // Outputs: 50
alert(rectObj.constructor.name) // Outputs: Rectangle
</script>
Use the
name
PropertyYou can use the
need an explanation for this answer? contact us directly to get an explanation for this answername
property of the object's constructor function to get the name of the class that is used to instantiated the object. Let's take a look an example: