Get the name of an object's type

前端 未结 20 2259
忘掉有多难
忘掉有多难 2020-11-21 22:37

Is there a JavaScript equivalent of Java\'s class.getName()?

20条回答
  •  名媛妹妹
    2020-11-21 22:46

    Use class.name. This also works with function.name.

    class TestA {}
    console.log(TestA.name); // "TestA"
    
    function TestB() {}
    console.log(TestB.name); // "TestB"
    

提交回复
热议问题