I am trying to get the instance name of my class.
The way I do this is a loop of all global objects and comparing it to this pointer.
It works in Chrome and FF, but in IE it is not. The problem is that global variables are not displayed in the window.
How can I iterate over global variables in IE?
PS: I know that it only works as long as there is only one instance, and I don't want to pass the instance name as a parameter.
function myClass()
{
this.myName = function ()
{
for (var name in this.global)
{
if (this.global[name] == this)
return name
}
}
}
function myClass_chrome()
{
this.myName = function ()
{
for (var name in window)
{
if (window[name] == this)
return name ;
}
} ;
}
myClass.prototype.global = this
var myVar = new myClass_chrome()
alert(myVar.myName() );
source
share