A very puzzling problem i am having with JavaScript. look at the code below..
az={
classes:{
test:function(){
this.hello=function(name){
alert('hello '+name);
}
}
},
getClass:function(name){
return az.classes[name];
}
};
var a=new az.classes['test']();
a.hello('foo');
var b= new az.getClass('test')();
b.hello();// fails !!!
in the code if you notice we have a class defined inside an object az.classes. when try to create an instance of that class by new az.classes['test](), it works and a.hello() executes fine. but when i call the method az.getClass('test'), which in turn returns the same constructor, but it fails when i say var b=new az.getClass('test'); here its saying b is undefined!! and b.hello() fails!! i do not understand this behaviour! what is the difference between new az.classes['test']() and new az.getClass('test'). Are they not the same thing??
var b= new (az.getClass('test'))();instead. then b will be like agetClass:function(name)