i have a problem with instanciate a class with the window object, i have a namespace call UTIL and i have this class:
var UTIL = { Classes : {}};
UTIL.Classes.ObservationVal = function(state, id, type, context, performer, addresee, query) {
this.query = query;
SPEECH.Classes.ActionVal.call(this,state, id, type, context, performer, addresee);
}
UTIL.Classes.ObservationVal.prototype = new SPEECH.Classes.ActionVal();
UTIL.Classes.ObservationVal.prototype.constructor = SPEECH.Classes.ObservationVal;
after, i have this code:
var name = "ObservationVal";
var clStr = "UTIL.Classes." + name;
var obj = new window[clStr]();
and this last line shows the error: “window[clStr] is not a constructor”
I don’t understand why fail the instanciate, when the class ObservationVal is defined out of namespace like this:
function ObservationVal(state, id, type, context, performer, addresee, query) {
//..
}
the instanciate with window works ok.
Thanks.
This is because
foo["bar.baz"]is not equal tofoo.bar.baz. You probably need something likewindow.UTIL.Classes[name]here.