PDPjs Now Uses ES6 Features
PDPjs is the first PCjs machine that now uses selected ES6 features, including:
- Classes
- Default Parameters
- const and let
- Computed Properties
- Octal and binary constants
- Template Literals (for string interpolation; i.e.: ${…})
The conversion from ES5 to ES6 classes was the most substantial change. The rest of the features have only been used sporadically, as I stumble across code that could benefit from the improvements in ES6 syntax.
Also, since only PDPjs has been converted thus far, I had to fork the shared code in /modules/shared/lib into its own ES6 folder in /modules/shared/es6. Once all PCjs machines have been converted to ES6, the contents of the shared /es6 folder will be folded back into the original /lib folder. In the interim (which will hopefully be short), any changes to shared code will have to be made in both places, and any attempt to run two or more machines on the same page with different shared modules will fail -- but that only affects users running uncompiled code.
You probably won't see a big difference in the compiled code, because I've configured Google's Closure Compiler to "transpile" to ES5. Even though all the browsers that PCjs supports now include support for all the ES6 features that I'm using (which isn't that much, as you can see from the above list), the problem is users, not browsers. Until it's a safe bet that nearly all users are running the current crop of browsers, I don't feel comfortable relying on ES6 browser support. At some point, I'll either decide to flip the switch, or add a small loader that detects your browser's capabilities and then loads the appropriate compiled code.