Get the name of an object's type

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

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

20条回答
  •  我寻月下人不归
    2020-11-21 23:04

    A little trick I use:

    function Square(){
        this.className = "Square";
        this.corners = 4;
    }
    
    var MySquare = new Square();
    console.log(MySquare.className); // "Square"
    

提交回复
热议问题