Is it possible to create a dynamic namespace in a javascript class?
I'm running into an issue w开发者_如何学JAVAhere I need to use this class twice on the same page but it uses the same namespace in both spots so it's failing.
you can always instantiate the class like this:
window['stuff'] = new Component()
window['stuff1'] = new Component()
so then you can refer to this instance as window.stuff and window.stuff1
is this what you mean?
var namespace1 = {};
var namespace2 = {};
var myObjMaker = function() {
this.a = blah;
this.function = bluh;
}
var makeObjInNS1 = myObjMaker.apply(namespace1);
var makeObjInNS2 = myObjMaker.apply(namespace2);
var makeGlobalObj = myObjMaker.apply(this);
精彩评论