|
98 | 98 | }
|
99 | 99 | ```
|
100 | 100 |
|
101 |
| - - For [performance reasons](http://jsperf.com/array-direct-assignment-vs-push/5) use direct assignment over Array#push |
102 |
| - - If you don't know array length use Array#push. |
| 101 | + - Always use array#push when appending new values to an array. |
103 | 102 |
|
104 | 103 | ```javascript
|
105 | 104 | var someStack = [];
|
106 | 105 |
|
107 |
| - // good |
| 106 | + // bad |
108 | 107 | someStack[someStack.length] = 'abracadabra';
|
109 | 108 |
|
110 | 109 | // good
|
|
513 | 512 |
|
514 | 513 | ## <a name='comments'>Comments</a>
|
515 | 514 |
|
| 515 | + - Documentation is highly recommended on Utility Modules. It is optional on all other types of Modules. |
| 516 | + - Don't over document. Opt for descriptive names of variables, functions, and returns over documenting the obvious. |
516 | 517 | - Use [JSDoc](http://usejsdoc.org) notation for commenting guidelines.
|
517 | 518 | - Use `/** ... */` for multiline comments.
|
518 | 519 |
|
|
792 | 793 |
|
793 | 794 | ## <a name='naming-conventions'>Naming Conventions</a>
|
794 | 795 |
|
795 |
| - - Avoid single letter names. Be descriptive with your naming. These get uglified anyways. |
| 796 | + - Avoid single letter names. Be descriptive with your naming. These get Uglified anyways. |
796 | 797 |
|
797 | 798 | ```javascript
|
798 | 799 | // bad
|
|
806 | 807 | }
|
807 | 808 | ```
|
808 | 809 |
|
809 |
| - - Use lower camelCase when naming objects, functions, and instances |
810 |
| -
|
811 |
| - ```javascript |
812 |
| - // bad |
813 |
| - var OBJEcttsssss = {}; |
814 |
| - var this_is_my_object = {}; |
815 |
| - var this-is-my-object = {}; |
816 |
| - function c() {}; |
817 |
| - var u = new user({ |
818 |
| - name: 'Bob Parr' |
819 |
| - }); |
820 |
| - |
821 |
| - // good |
822 |
| - var thisIsMyObject = {}; |
823 |
| - function thisIsMyFunction() {}; |
824 |
| - var user = new User({ |
825 |
| - name: 'Bob Parr' |
826 |
| - }); |
827 |
| - ``` |
828 |
| -
|
829 |
| - - Use PascalCase when naming constructors or classes |
| 810 | + - Use PascalCase when naming Views, Constructors, Classes, Models, and Collections. |
830 | 811 |
|
831 | 812 | ```javascript
|
832 | 813 | // bad
|
|
848 | 829 | });
|
849 | 830 | ```
|
850 | 831 |
|
| 832 | + - Use lower camelCase for everything else (e.g.- objects, functions, and instances). |
| 833 | +
|
| 834 | + ```javascript |
| 835 | + // bad |
| 836 | + var OBJEcttsssss = {}; |
| 837 | + var this_is_my_object = {}; |
| 838 | + var this-is-my-object = {}; |
| 839 | + function c() {}; |
| 840 | + var u = new user({ |
| 841 | + name: 'Bob Parr' |
| 842 | + }); |
| 843 | + |
| 844 | + // good |
| 845 | + var thisIsMyObject = {}; |
| 846 | + function thisIsMyFunction() {}; |
| 847 | + var user = new User({ |
| 848 | + name: 'Bob Parr' |
| 849 | + }); |
| 850 | + ``` |
| 851 | +
|
851 | 852 | - When saving a reference to `this` use `self`.
|
852 | 853 |
|
853 | 854 | ```javascript
|
|
0 commit comments