|
3 | 3 | *A mostly reasonable approach to JavaScript*
|
4 | 4 |
|
5 | 5 |
|
6 |
| -## <a name='TOC'>Table of Contents</a> |
| 6 | +## <a name="TOC">Table of Contents</a> |
7 | 7 |
|
8 | 8 | 1. [Types](#types)
|
9 | 9 | 1. [Objects](#objects)
|
|
34 | 34 | 1. [Contributors](#contributors)
|
35 | 35 | 1. [License](#license)
|
36 | 36 |
|
37 |
| -## <a name='types'>Types</a> |
| 37 | +## <a name="types">Types</a> |
38 | 38 |
|
39 | 39 | - **Primitives**: When you access a primitive type you work directly on its value
|
40 | 40 |
|
|
69 | 69 |
|
70 | 70 | **[[⬆]](#TOC)**
|
71 | 71 |
|
72 |
| -## <a name='objects'>Objects</a> |
| 72 | +## <a name="objects">Objects</a> |
73 | 73 |
|
74 | 74 | - Use the literal syntax for object creation.
|
75 | 75 |
|
|
100 | 100 | ```
|
101 | 101 | **[[⬆]](#TOC)**
|
102 | 102 |
|
103 |
| -## <a name='arrays'>Arrays</a> |
| 103 | +## <a name="arrays">Arrays</a> |
104 | 104 |
|
105 | 105 | - Use the literal syntax for array creation
|
106 | 106 |
|
|
161 | 161 | **[[⬆]](#TOC)**
|
162 | 162 |
|
163 | 163 |
|
164 |
| -## <a name='strings'>Strings</a> |
| 164 | +## <a name="strings">Strings</a> |
165 | 165 |
|
166 | 166 | - Use single quotes `''` for strings
|
167 | 167 |
|
|
249 | 249 | **[[⬆]](#TOC)**
|
250 | 250 |
|
251 | 251 |
|
252 |
| -## <a name='functions'>Functions</a> |
| 252 | +## <a name="functions">Functions</a> |
253 | 253 |
|
254 | 254 | - Function expressions:
|
255 | 255 |
|
|
306 | 306 |
|
307 | 307 |
|
308 | 308 |
|
309 |
| -## <a name='properties'>Properties</a> |
| 309 | +## <a name="properties">Properties</a> |
310 | 310 |
|
311 | 311 | - Use dot notation when accessing properties.
|
312 | 312 |
|
|
341 | 341 | **[[⬆]](#TOC)**
|
342 | 342 |
|
343 | 343 |
|
344 |
| -## <a name='variables'>Variables</a> |
| 344 | +## <a name="variables">Variables</a> |
345 | 345 |
|
346 | 346 | - Always use `var` to declare variables. Not doing so will result in global variables. We want to avoid polluting the global namespace. Captain Planet warned us of that.
|
347 | 347 |
|
|
449 | 449 | **[[⬆]](#TOC)**
|
450 | 450 |
|
451 | 451 |
|
452 |
| -## <a name='hoisting'>Hoisting</a> |
| 452 | +## <a name="hoisting">Hoisting</a> |
453 | 453 |
|
454 | 454 | - Variable declarations get hoisted to the top of their scope, their assignment does not.
|
455 | 455 |
|
|
540 | 540 |
|
541 | 541 |
|
542 | 542 |
|
543 |
| -## <a name='conditionals'>Conditional Expressions & Equality</a> |
| 543 | +## <a name="conditionals">Conditional Expressions & Equality</a> |
544 | 544 |
|
545 | 545 | - Use `===` and `!==` over `==` and `!=`.
|
546 | 546 | - Conditional expressions are evaluated using coercion with the `ToBoolean` method and always follow these simple rules:
|
|
588 | 588 | **[[⬆]](#TOC)**
|
589 | 589 |
|
590 | 590 |
|
591 |
| -## <a name='blocks'>Blocks</a> |
| 591 | +## <a name="blocks">Blocks</a> |
592 | 592 |
|
593 | 593 | - Use braces with all multi-line blocks.
|
594 | 594 |
|
|
617 | 617 | **[[⬆]](#TOC)**
|
618 | 618 |
|
619 | 619 |
|
620 |
| -## <a name='comments'>Comments</a> |
| 620 | +## <a name="comments">Comments</a> |
621 | 621 |
|
622 | 622 | - Use `/** ... */` for multiline comments. Include a description, specify types and values for all parameters and return values.
|
623 | 623 |
|
|
684 | 684 | **[[⬆]](#TOC)**
|
685 | 685 |
|
686 | 686 |
|
687 |
| -## <a name='whitespace'>Whitespace</a> |
| 687 | +## <a name="whitespace">Whitespace</a> |
688 | 688 |
|
689 | 689 | - Use soft tabs set to 2 spaces
|
690 | 690 |
|
|
779 | 779 | .call(tron.led);
|
780 | 780 | ```
|
781 | 781 |
|
782 |
| -## <a name='leading-commas'>Leading Commas</a> |
| 782 | +## <a name="leading-commas">Leading Commas</a> |
783 | 783 |
|
784 | 784 | - **Nope.**
|
785 | 785 |
|
|
814 | 814 | **[[⬆]](#TOC)**
|
815 | 815 |
|
816 | 816 |
|
817 |
| -## <a name='semicolons'>Semicolons</a> |
| 817 | +## <a name="semicolons">Semicolons</a> |
818 | 818 |
|
819 | 819 | - **Yup.**
|
820 | 820 |
|
|
841 | 841 | **[[⬆]](#TOC)**
|
842 | 842 |
|
843 | 843 |
|
844 |
| -## <a name='type-coercion'>Type Casting & Coercion</a> |
| 844 | +## <a name="type-coercion">Type Casting & Coercion</a> |
845 | 845 |
|
846 | 846 | - Perform type coercion at the beginning of the statement.
|
847 | 847 | - Strings:
|
|
913 | 913 | **[[⬆]](#TOC)**
|
914 | 914 |
|
915 | 915 |
|
916 |
| -## <a name='naming-conventions'>Naming Conventions</a> |
| 916 | +## <a name="naming-conventions">Naming Conventions</a> |
917 | 917 |
|
918 | 918 | - Avoid single letter names. Be descriptive with your naming.
|
919 | 919 |
|
|
1027 | 1027 | **[[⬆]](#TOC)**
|
1028 | 1028 |
|
1029 | 1029 |
|
1030 |
| -## <a name='accessors'>Accessors</a> |
| 1030 | +## <a name="accessors">Accessors</a> |
1031 | 1031 |
|
1032 | 1032 | - Accessor functions for properties are not required
|
1033 | 1033 | - If you do make accessor functions use getVal() and setVal('hello')
|
|
1081 | 1081 | **[[⬆]](#TOC)**
|
1082 | 1082 |
|
1083 | 1083 |
|
1084 |
| -## <a name='constructors'>Constructors</a> |
| 1084 | +## <a name="constructors">Constructors</a> |
1085 | 1085 |
|
1086 | 1086 | - Assign methods to the prototype object, instead of overwriting the prototype with a new object. Overwriting the prototype makes inheritance impossible: by resetting the prototype you'll overwrite the base!
|
1087 | 1087 |
|
|
1166 | 1166 | **[[⬆]](#TOC)**
|
1167 | 1167 |
|
1168 | 1168 |
|
1169 |
| -## <a name='modules'>Modules</a> |
| 1169 | +## <a name="modules">Modules</a> |
1170 | 1170 |
|
1171 | 1171 | - 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.
|
1172 | 1172 | - The file should be named with camelCase, live in a folder with the same name, and match the name of the single export.
|
|
1196 | 1196 | **[[⬆]](#TOC)**
|
1197 | 1197 |
|
1198 | 1198 |
|
1199 |
| -## <a name='jquery'>jQuery</a> |
| 1199 | +## <a name="jquery">jQuery</a> |
1200 | 1200 |
|
1201 | 1201 | - Prefix jQuery object variables with a `$`.
|
1202 | 1202 |
|
|
1261 | 1261 | **[[⬆]](#TOC)**
|
1262 | 1262 |
|
1263 | 1263 |
|
1264 |
| -## <a name='es5'>ECMAScript 5 Compatability</a> |
| 1264 | +## <a name="es5">ECMAScript 5 Compatability</a> |
1265 | 1265 |
|
1266 | 1266 | - Refer to [Kangax](https://twitter.com/kangax/)'s ES5 [compatibility table](http://kangax.github.com/es5-compat-table/)
|
1267 | 1267 |
|
1268 | 1268 | **[[⬆]](#TOC)**
|
1269 | 1269 |
|
1270 | 1270 |
|
1271 |
| -## <a name='testing'>Testing</a> |
| 1271 | +## <a name="testing">Testing</a> |
1272 | 1272 |
|
1273 | 1273 | - **Yup.**
|
1274 | 1274 |
|
|
1281 | 1281 | **[[⬆]](#TOC)**
|
1282 | 1282 |
|
1283 | 1283 |
|
1284 |
| -## <a name='performance'>Performance</a> |
| 1284 | +## <a name="performance">Performance</a> |
1285 | 1285 |
|
1286 | 1286 | - [String vs Array Concat](http://jsperf.com/string-vs-array-concat/2)
|
1287 | 1287 | - [Try/Catch Cost In a Loop](http://jsperf.com/try-catch-in-loop-cost)
|
|
1293 | 1293 | **[[⬆]](#TOC)**
|
1294 | 1294 |
|
1295 | 1295 |
|
1296 |
| -## <a name='resources'>Resources</a> |
| 1296 | +## <a name="resources">Resources</a> |
1297 | 1297 |
|
1298 | 1298 |
|
1299 | 1299 | **Read This**
|
|
1337 | 1337 |
|
1338 | 1338 | **[[⬆]](#TOC)**
|
1339 | 1339 |
|
1340 |
| -## <a name='in-the-wild'>In the Wild</a> |
| 1340 | +## <a name="in-the-wild">In the Wild</a> |
1341 | 1341 |
|
1342 | 1342 | This is a list of organizations that are using this style guide. Send us a pull request or open an issue and we'll add you to the list.
|
1343 | 1343 |
|
|
1347 | 1347 | - **MinnPost**: [MinnPost/javascript](//github.com/MinnPost/javascript)
|
1348 | 1348 | - **Shutterfly**: [shutterfly/javascript](//github.com/shutterfly/javascript)
|
1349 | 1349 |
|
1350 |
| -## <a name='guide-guide'>The JavaScript Style Guide Guide</a> |
| 1350 | +## <a name="guide-guide">The JavaScript Style Guide Guide</a> |
1351 | 1351 |
|
1352 | 1352 | - [Reference](//github.com/airbnb/javascript/wiki/The-JavaScript-Style-Guide-Guide)
|
1353 | 1353 |
|
1354 |
| -## <a name='authors'>Contributors</a> |
| 1354 | +## <a name="authors">Contributors</a> |
1355 | 1355 |
|
1356 | 1356 | - [View Contributors](https://github.com/airbnb/javascript/graphs/contributors)
|
1357 | 1357 |
|
1358 | 1358 |
|
1359 |
| -## <a name='license'>License</a> |
| 1359 | +## <a name="license">License</a> |
1360 | 1360 |
|
1361 | 1361 | (The MIT License)
|
1362 | 1362 |
|
|
0 commit comments