Embarking on a sizable JavaScript project, I've decided to organize everything within one or more namespaces to limit the use of global scope. Currently, only one element exists in the global scope.
To maintain organization, I prefer keeping each class in its own file rather than using "modules," akin to other programming languages.
I developed a compilation script using NodeJS to merge all the files into a single JavaScript file by the end of the day.
Although I had what I thought was a solid method, I'm encountering difficulties with getting JSDoc(3) to cooperate. This makes me question if my approach is incorrect or if there's a particular trick regarding JSDoc that I might be overlooking.
In the source code, each namespace corresponds to a folder, and each class has a file with an identical name.
The structure of each class file resembles this:
var BaseNS = BaseNS || {};
BaseNS.SubNS = BaseNS.SubNS || {};
BaseNS.SubNS.MyClass = (function() {
function MyClass() {
}
Object.defineProperties(MyClass.prototype, {
'someProp', {
getter: function() { return this._someProp = this._someProp || 0; },
setter: function(val) { this._someProp = val; }
}
// ... more
});
MyClass.prototype.someMethod = function() {};
// ... more
return MyClass;
}}());
When compiled together, the script manages dependencies to arrange classes in the correct order while removing redundant namespace declarations.
This method seems clean and straightforward, but writing JSDoc documentation poses a challenge in achieving the desired results.
My intention is to implement a "class-like" structure for this application, which operates largely independent of the DOM. Additionally, I aim to develop the entire project in vanilla, modern JavaScript without utilizing tools like RequireJS.
Any suggestions on how to document this effectively or improve the organization?
Thank you.