I am opening this issue to continue the discussion from LaserWeb/deprecated-LaserWeb3#97.
Since we're starting a new version of LaserWeb, I feel it's important we discuss a few options so we do not end up having to rewrite parts of the code in the future again.
So for some context, ES2015 is the new version of JS that was published and is starting to be supported my the major browsers. It brings some significant changes from previous JS, the ones I find more important to writing complex apps are modules and classes. I think LaserWeb codebase would greatly benefit from using the new module system. It basically allows each file to declare and explicitly import its dependencies which makes the code much easier to reason about.
I am suggesting we adopt this standard. It's already 1 year old so it's not like it was just released. While it's not the most well supported standard now, but it will in a couple of months once people start upgrading to newer browser versions. We can use a ES6 to ES5 JS compiler like Babel until that happens. It generates code that works under all browsers.
@arthurwolf brought the point that it will drive contributors away. Due to cleaner architecture and syntax, people used to pretty much every other programming language than front-end JS will feel more at home and since code will be much easier to reason about people will understand the code faster and contribute more. Besides most JS devs are already used to the export/import pattern from Node.
Aside from modules, classes would also help. The model that @lautr3k is proposing is using class inheritance under the hood anyway, but instead of being explicitly specified in the code it's using jQuery helper methods. It's not the most easy to understand model, I've had to reach out for the jQuery docs multiple times to understand what it really does.
I've pushed the first version of the conversion to es6 branch at: https://github.com/openhardwarecoza/LaserWeb4/tree/es6
@lautr3k The only real change I had to do from your architecture was to get rid of the dependency on the lw.get_module
from the dock code and replace it with pub/sub pattern. That way the dock code does not depend directly on its parent, but the other way around.
Let me know what you guys think. If you still feel ES5 is the way to go then I will get rid of this branch, but if you agree it's the best way to future-proof LaserWeb code, then we can decide on the best way to generate the ES5 from ES6 to make it the least intrusive way on development possible.
By the way, I've not coded JS in years, so it's possible I might have messed up something.