I have a function, which iterates over some objects, and I want to then use the variable name of the object being iterated over. Currently I maintain a duplicate list of names, and refer to them by array index. This seems unnecessary. The whole thing is in an enclosure.
In principle, I can see two ways to do it.
One is to use the list of names, and somehow refer the the variables named such, and the other is to somehow determine the variable name from the variable itself (held in an array).
Is this possible, or should I be looking at a completely different approach?
(function(){
var a = {p:true,b:true};
var b = {em:true,i:true};
var c = {h1:true,strong:true};
var x = function(tagName){
var typedefnames = ["a","b","c"]
var typedefs = [a,b,c];
var types = {}
var i;
for( i=0; i<typedefs.length; i++ )
if( typedefs[i][ tagName ] )
types[ typedefnames[i] ] = true
else
types[ typedefnames[i] ] = false
return types;
}
console.log(x("p"))
// { a:true, b:false, c:false }
}())