Manage Access & Namespaces via Closures
Anonymous Closures allow to maintain modularity and to prevent exposing the private modules data.
Global variables have unclear scope leading to tough manageable apps.
Invocation of the global variables is expensive, because it checks entire scope depth.
The objects with the same names might be overridden if those are not within the separate namespaces.
Here are few points how to start doing better:
- use namespaces to prevent conflicts & unexpected overrides;
- use anonymous closures to encapsulate & isolate your app private data;
- return the result object with the only api that you want to expose;
- avoid direct global variables usage, use imports istead;>
- group file content around needed data.
No comments:
Post a Comment