javascript tutorial - [Solved-5 Solutions] Commonly accepted best practices around code organization in javascript
- javascript - java script - javascript array
Problem:
Commonly accepted best practices around code organization in javascript
Solution 1:
It would be a lot nicer if javascript had namespaces built in, but We find that organizing things like Dustin Diaz describes here helps me a lot.
Solution 2:
We can break up our scripts into separate files for development, then create a "release" version where we cram them all together and run YUWE Compressor or something similar on it.
Solution 3:
The code organization requires adoption of conventions and documentation standards:
Namespace code for a physical file;Exc = {};
Group classes in these namespaces javascript;
Set Prototypes or related functions or classes for representing real-world objects;
Set conventions to improve the code. For example, group all of its internal functions or methods in its class attribute of an object type.
Make documentation of namespaces, classes, methods and variables. Where necessary also discuss some of the code (some FIs and Fors, they usually implement important logic of the code).
Solution 4:
We was able to successfully apply the Javascript Module Pattern to an Ext JS application at my previous job. It provided a simple way to create nicely encapsulated code.
Solution 5:
Organising our code in a Jquery centric NameSpace way may look as follows... and will not clash with other Javascript API's like Prototype, Ext either.