Pseudo-typed JavaScript
How to identify variable types using a consistent naming scheme.
No static typing?
Every developer knows that JavaScript is not a static typed language, a useful feature eliminating lots of bugs. A language like Typescript has been created as a remedy to that important lack of safety. Even for code modules counting less than a few tens of lines, it’s easy to forget what kind of type is exactly a variable or constant declared at the begining of the file and then make a mistake when assining a wrong type to a variable.
11tyTips follows the TypesJS naming scheme for a cleaner and more meaningful code. Here is how it looks in action the following listing is the service worker file integrated in 11tyTips which relies heavily on the excellent article by Thomas Hunter II: On using Service Workers with Static Content :
11tyTips/source/matrix/assets/scripts/js/parts/_service_worker_.js
Prism
As a side note, it’s worth noting that a declaration like
const ID_s = ‘{{A_o.ID_s}}’
is only made possible by the use of a minification filter during which Nunjucks variables are expanded before writing the JavaScript file! But it’s another story: minifying…