javascript get type/instance name

后端 未结 5 1919
一个人的身影
一个人的身影 2021-02-07 01:06

Is there a reliable way of getting the instance of a JavaScript object?

For example, relying on the fake \'obj.getInstance()\' function.

var         


        
5条回答
  •  臣服心动
    2021-02-07 01:45

    You can do :

        get(){ // Method
            for ( var nameOfVariable in window ) 
                if (eval(nameOfVariable +"=== this")) return nameOfVariable;// true if variable name is instace of this
            return "";            
        }
    

提交回复
热议问题