How to get the instance name of an object

后端 未结 7 1333
萌比男神i
萌比男神i 2021-01-15 00:07

I use the below code to write code to query a web method in a specified interval.

now in the this.Poll function I have to do

this.tmo = setTimeo         


        
7条回答
  •  执念已碎
    2021-01-15 00:41

    You could also use:

    i.e.

    var name = findInstanceOf(cPoll);
    
    function findInstanceOf(obj) {
        for (var v in window) {
            try {
                if (window[v] instanceof obj)
                    return v;
            } catch(e) { }
        };
        return false;
    }
    

    From http://www.liam-galvin.co.uk/2010/11/24/javascript-find-instance-name-of-an-object/#read

提交回复
热议问题