3 ms·
For front-end, just start every .js file with: (function() {"use strict"; and end with })(); and write all global variables in ALL_CAPS, or with Big Fir
by z3t4 10y ago
For front-end, just start every .js file with:
(function() {"use strict";
and end with
})();
and write all global variables in ALL_CAPS, or with Big First Letter if it's a constructor function / Class.
If you want global functions, give them name-spaces, like UTIL.handyFunction = function handyFunction() {}
- Animats 10y agoThat's how to fix code that you write. It doesn't help with code that you import or copy from elsewhere.
- z3t4 10y agoSometime it feels like people intentionally make their code hard to copy/reuse ... While the code might do awesome stuff, it will however not live long due to manageability problems. When the author reads his own code six moth later, he's unable to fix that bug or add that feature, because he has forgot about the hundreds of global variables, functions and couplings he had in his head when writing the program.