|
1 |
| -# Airbnb JavaScript Style Guide() { |
| 1 | +# ZocDoc JavaScript Style Guide() { |
2 | 2 |
|
3 |
| -*A mostly reasonable approach to JavaScript* |
| 3 | +### Fork of https://github.com/airbnb/javascript |
4 | 4 |
|
| 5 | +*A mostly reasonable approach to JavaScript* |
5 | 6 |
|
6 | 7 | ## <a name='TOC'>Table of Contents</a>
|
7 | 8 |
|
|
616 | 617 |
|
617 | 618 | ## <a name='comments'>Comments</a>
|
618 | 619 |
|
619 |
| - - Use `/** ... */` for multiline comments. Include a description, specify types and values for all parameters and return values. |
| 620 | + - Use `/** ... */` for multiline comments. Include a description, specify types and values for all parameters and return values. This is __required__ for shared components or apis. |
620 | 621 |
|
621 | 622 | ```javascript
|
622 | 623 | // bad
|
|
678 | 679 | }
|
679 | 680 | ```
|
680 | 681 |
|
681 |
| - - Prefixing your comments with `FIXME` or `TODO` helps other developers quickly understand if you're pointing out a problem that needs to be revisited, or if you're suggesting a solution to the problem that needs to be implemented. These are different than regular comments because they are actionable. The actions are `FIXME -- need to figure this out` or `TODO -- need to implement`. Always finish your `TODO` or `FIXME` comments with `: NAME` such as `TODO: Guofu` |
| 682 | + - Prefixing your comments with `FIXME` or `TODO` helps other developers quickly understand if you're pointing out a problem that needs to be revisited, or if you're suggesting a solution to the problem that needs to be implemented. These are different than regular comments because they are actionable. The actions are `FIXME -- need to figure this out` or `TODO -- need to implement`. Always finish your `TODO` or `FIXME` comments with `: Name` such as `TODO: Guofu` |
682 | 683 |
|
683 | 684 | - Use `// FIXME:` to annotate problems
|
684 | 685 |
|
|
754 | 755 | breed: 'Bernese Mountain Dog'
|
755 | 756 | });
|
756 | 757 | ```
|
757 |
| - - Place an empty newline at the end of the file. |
758 |
| - |
759 |
| - ```javascript |
760 |
| - // bad |
761 |
| - (function(global) { |
762 |
| - // ...stuff... |
763 |
| - })(this); |
764 |
| - ``` |
765 |
| - |
766 |
| - ```javascript |
767 |
| - // good |
768 |
| - (function(global) { |
769 |
| - // ...stuff... |
770 |
| - })(this); |
771 |
| -
|
772 |
| - ``` |
773 | 758 |
|
774 | 759 | - Use indentation when making long method chains.
|
775 | 760 |
|
|
974 | 959 | });
|
975 | 960 | ```
|
976 | 961 |
|
977 |
| - - Use PascalCase when naming constructors or classes |
| 962 | + - Use PascalCase when naming constructors, classes, directories, files, or modules |
978 | 963 |
|
979 | 964 | ```javascript
|
980 | 965 | // bad
|
|
1224 | 1209 |
|
1225 | 1210 | ## <a name='modules'>Modules</a>
|
1226 | 1211 |
|
1227 |
| - - The module should start with a `!`. This ensures that if a malformed module forgets to include a final semicolon there aren't errors in production when the scripts get concatenated. |
1228 |
| - - The file should be named with camelCase, live in a folder with the same name, and match the name of the single export. |
1229 |
| - - Add a method called noConflict() that sets the exported module to the previous version and returns this one. |
1230 |
| - - Always declare `'use strict';` at the top of the module. |
| 1212 | + - The file should start with Cassette references to its dependencies |
| 1213 | + - The code should start with a `;`. This ensures that if a malformed module forgets to include a final semicolon there aren't errors in production when the scripts get concatenated. |
| 1214 | + - The file should be named with PascalCase |
| 1215 | + - The file should consist of a IIFE that passes in the result of a call to `ZD.module` with the module name |
1231 | 1216 |
|
1232 | 1217 | ```javascript
|
1233 |
| - // fancyInput/fancyInput.js |
1234 |
| -
|
1235 |
| - !function(global) { |
1236 |
| - 'use strict'; |
| 1218 | + // @reference /App_Scripts/Framework |
1237 | 1219 |
|
1238 |
| - var previousFancyInput = global.FancyInput; |
| 1220 | + ;(function(fancyInput) { |
1239 | 1221 |
|
1240 |
| - function FancyInput(options) { |
1241 |
| - this.options = options || {}; |
1242 |
| - } |
1243 |
| -
|
1244 |
| - FancyInput.noConflict = function noConflict() { |
1245 |
| - global.FancyInput = previousFancyInput; |
1246 |
| - return FancyInput; |
1247 |
| - }; |
| 1222 | + fancyInput.FancyInput = function FancyInput(options) { |
| 1223 | + this.options = options || {}; |
| 1224 | + }; |
1248 | 1225 |
|
1249 |
| - global.FancyInput = FancyInput; |
1250 |
| - }(this); |
| 1226 | + }(ZD.module('FancyInput')); |
1251 | 1227 | ```
|
1252 | 1228 |
|
1253 | 1229 | **[[⬆]](#TOC)**
|
|
0 commit comments