I am used to the following syntax which is - I believe - widely used:
var foo = foo || {};
(function() {
foo.bar = function(){
return this;
};
foo.bar.prototype.stuff = null;
foo.bar.prototype.do = function(){...};
})();
It could be done with or without closure.
I use the foo.bar.prototype.stuff syntax so as to not have all the definitions in the constructor itself.
With ECS6 I experimented with this syntax:
class Foo{};
class Bar{
constructor(){
this.stuff = null;
}
get moreStuff(){ return this.stuff++;}
do(){...}
}
Foo.Bar = Bar;
module.exports = { Foo };
I find it very convenient that intellisense works in Visual Studio Code when using this syntax.
Can anyone see any issue with this syntax and if so amend it propose a better one?
I read this post How do I declare a namespace in JavaScript? and found many proposed syntax but most were given before ECS6.