Take this code for example:
(function(foo) {
foo.init = function() {};
// other public/private methods here.
return foo;
}(window.FOO = window.FOO || {}));
I call it like so:
FOO.init();
Is it possible to allow the user to define what FOO is?
In other words, I need to allow multiple instances of window.FOO; for example, like window.BILLY and window.BAZ (or, should it be window.billy.FOO and window.baz.FOO?).
In other words, is there an elegant way to (allow the user to) namespace a “namespace” using a variation of the above construct and initialization?
If I understand you correctly you want to change the above code such that the name of
FOOis dynamic. You can do that, using the [] property accessor:But I’m not sure what sense this would make, your example is very abstract.