Javascript获取变量的名称及实例

//
// js获取变量名
//

function class(){}
var arr=new Array();
window['class1']=new class();
arr.add(window['class1']);
for(var c in arr){
  alert(c);
}

//
// js获取实例
//

var arr=new Array();
function dialog(){
  array.push(this);
}
dialog.prototype.show=function(){
   document.body.innserHTML("<a href='javascript:closeDialogs()'>关闭所有对话框</a>");
   // some code in here
}
dialog.prototype.close=function(){
   // some code in here
}
function closeDialogs(){
  for(var i in arr){
     arr[i].close(); 
  }
}

在实际处理一些问题时候,比如需要将变量的实例编码进html中时候,可以利用数组去获取实例变量
原文地址:https://www.cnblogs.com/newmin/p/2010271.html