Having an issue when trying to instantiate a class using the window object. I have a namespace called UTIL and within it, there is a class defined as follows:
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;
Later on, I have the following code snippet:
var name = "ObservationVal";
var clStr = "UTIL.Classes." + name;
var obj = new window[clStr]();
However, this last line results in the error: "window[clStr] is not a constructor"
I am confused as to why the instantiation fails, given that the ObservationVal class is defined outside the namespace like this:
function ObservationVal(state, id, type, context, performer, addresee, query) {
//..
}
Instantiating with window works fine in this case. Thank you.