Is there a way to do the following without using eval()
?
The following function accepts an array of strings where the strings are object names. I iterate over them to ensure that none of them are undefined. I'd like to be able to do this without using eval()
function hasMissingDependencies(dependencies) {
var missingDependencies = [];
for (var i = 0; i < dependencies.length; i++) {
if (eval('typeof ' + dependencies[i]) === 'undefined') {
missingDependencies.push(dependencies[i]);
}
}
if (missingDependencies.length > 0) {
return true;
}
return false;
}
With this, I'm able to pass something like the following and get what I want:
alert(hasMissingDependencies(['App.FooObject', 'App.BarObject']));
I'd prefer to not use eval()
but haven't found another way to check if an object is undefined when the object names are passed as strings.