So, we all know that ES6's introduced syntax is definitely sugar over what we've been doing, previously. That being said, we still don't have namespaces (which would be nice...)
The problem that I'm trying to solve is converting old code into es6. This old code was doing something like:
window.foo = {
init: function() {
},
otherFoo: {
init: function() {
}
}
}
I was able to have my "modules" in separate files, and add them to my global "foo" that existed in window.
What I'd like to do instead, is create my separate modules, import them into my main JS file, and nest my classes within foo
, like so:
import OtherFoo from './otherfoo';
class Foo {
static init() {
}
static get OtherFoo() {
return OtherFoo;
}
}
It works, so it's not a question if how I can make it work, it's a question of whether or not I should? We in the javascript community tend to do things just because we can, but I like to avoid that line.