diff --git a/README.md b/README.md index 114758b3..8c1a265a 100644 --- a/README.md +++ b/README.md @@ -47,7 +47,7 @@ ## Types - - **Primitives**: When you access a primitive type you work directly on its value. + - [1.1](#1.1) **Primitives**: When you access a primitive type you work directly on its value. + `string` + `number` @@ -63,7 +63,7 @@ console.log(foo, bar); // => 1, 9 ``` - - **Complex**: When you access a complex type you work on a reference to its value. + - [1.2](#1.2) **Complex**: When you access a complex type you work on a reference to its value. + `object` + `array` @@ -82,7 +82,7 @@ ## References - - Use `const` for all of your references; avoid using `var`. + - [2.1](#2.1) Use `const` for all of your references; avoid using `var`. > Why? This ensures that you can't reassign your references (mutation), which can lead to bugs and difficult to comprehend code. @@ -96,7 +96,7 @@ const b = 2; ``` - - If you must mutate references, use `let` instead of `var`. + - [2.2](#2.2) If you must mutate references, use `let` instead of `var`. > Why? `let` is block-scoped rather than function-scoped like `var`. @@ -114,7 +114,7 @@ } ``` - - Note that both `let` and `const` are block-scoped. + - [2.3](#2.3) Note that both `let` and `const` are block-scoped. ```javascript // const and let only exist in the blocks they are defined in. @@ -130,7 +130,7 @@ ## Objects - - Use the literal syntax for object creation. + - [3.1](#3.1) Use the literal syntax for object creation. ```javascript // bad @@ -140,7 +140,7 @@ const item = {}; ``` - - Don't use [reserved words](http://es5.github.io/#x7.6.1) as keys. It won't work in IE8. [More info](https://github.com/airbnb/javascript/issues/61). + - [3.2](#3.2) Don't use [reserved words](http://es5.github.io/#x7.6.1) as keys. It won't work in IE8. [More info](https://github.com/airbnb/javascript/issues/61). ```javascript // bad @@ -156,7 +156,7 @@ }; ``` - - Use readable synonyms in place of reserved words. + - [3.3](#3.3) Use readable synonyms in place of reserved words. ```javascript // bad @@ -176,7 +176,7 @@ ``` - - Use computed property names when creating objects with dynamic property names. + - [3.4](#3.4) Use computed property names when creating objects with dynamic property names. > Why? They allow you to define all the properties of an object in one place. @@ -202,7 +202,7 @@ ``` - - Use object method shorthand. + - [3.5](#3.5) Use object method shorthand. ```javascript // bad @@ -225,7 +225,7 @@ ``` - - Use property value shorthand. + - [3.6](#3.6) Use property value shorthand. > Why? It is shorter to write and descriptive. @@ -243,7 +243,7 @@ }; ``` - - Group your shorthand properties at the beginning of your object declaration. + - [3.7](#3.7) Group your shorthand properties at the beginning of your object declaration. > Why? It's easier to tell which properties are using the shorthand. @@ -276,7 +276,7 @@ ## Arrays - - Use the literal syntax for array creation. + - [4.1](#4.1) Use the literal syntax for array creation. ```javascript // bad @@ -286,7 +286,7 @@ const items = []; ``` - - Use Array#push instead of direct assignment to add items to an array. + - [4.2](#4.2) Use Array#push instead of direct assignment to add items to an array. ```javascript const someStack = []; @@ -300,7 +300,7 @@ ``` - - Use array spreads `...` to copy arrays. + - [4.3](#4.3) Use array spreads `...` to copy arrays. ```javascript // bad @@ -315,7 +315,7 @@ // good const itemsCopy = [...items]; ``` - - To convert an array-like object to an array, use Array#from. + - [4.4](#4.4) To convert an array-like object to an array, use Array#from. ```javascript const foo = document.querySelectorAll('.foo'); @@ -326,7 +326,7 @@ ## Destructuring - - Use object destructuring when accessing and using multiple properties of an object. + - [5.1](#5.1) Use object destructuring when accessing and using multiple properties of an object. > Why? Destructuring saves you from creating temporary references for those properties. @@ -351,7 +351,7 @@ } ``` - - Use array destructuring. + - [5.2](#5.2) Use array destructuring. ```javascript const arr = [1, 2, 3, 4]; @@ -364,7 +364,7 @@ const [first, second] = arr; ``` - - Use object destructuring for multiple return values, not array destructuring. + - [5.3](#5.3) Use object destructuring for multiple return values, not array destructuring. > Why? You can add new properties over time or change the order of things without breaking call sites. @@ -393,7 +393,7 @@ ## Strings - - Use single quotes `''` for strings. + - [6.1](#6.1) Use single quotes `''` for strings. ```javascript // bad @@ -403,8 +403,8 @@ const name = 'Capt. Janeway'; ``` - - Strings longer than 80 characters should be written across multiple lines using string concatenation. - - Note: If overused, long strings with concatenation could impact performance. [jsPerf](http://jsperf.com/ya-string-concat) & [Discussion](https://github.com/airbnb/javascript/issues/40). + - [6.2](#6.2) Strings longer than 80 characters should be written across multiple lines using string concatenation. + - [6.3](#6.3) Note: If overused, long strings with concatenation could impact performance. [jsPerf](http://jsperf.com/ya-string-concat) & [Discussion](https://github.com/airbnb/javascript/issues/40). ```javascript // bad @@ -423,7 +423,7 @@ ``` - - When programmatically building up strings, use template strings instead of concatenation. + - [6.4](#6.4) When programmatically building up strings, use template strings instead of concatenation. > Why? Template strings give you a readable, concise syntax with proper newlines and string interpolation features. @@ -449,7 +449,7 @@ ## Functions - - Use function declarations instead of function expressions. + - [7.1](#7.1) Use function declarations instead of function expressions. > Why? Function declarations are named, so they're easier to identify in call stacks. Also, the whole body of a function declaration is hoisted, whereas only the reference of a function expression is hoisted. This rule makes it possible to always use [Arrow Functions](#arrow-functions) in place of function expressions. @@ -463,7 +463,7 @@ } ``` - - Function expressions: + - [7.2](#7.2) Function expressions: ```javascript // immediately-invoked function expression (IIFE) @@ -472,8 +472,8 @@ })(); ``` - - Never declare a function in a non-function block (if, while, etc). Assign the function to a variable instead. Browsers will allow you to do it, but they all interpret it differently, which is bad news bears. - - **Note:** ECMA-262 defines a `block` as a list of statements. A function declaration is not a statement. [Read ECMA-262's note on this issue](http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-262.pdf#page=97). + - [7.3](#7.3) Never declare a function in a non-function block (if, while, etc). Assign the function to a variable instead. Browsers will allow you to do it, but they all interpret it differently, which is bad news bears. + - [7.4](#7.4) **Note:** ECMA-262 defines a `block` as a list of statements. A function declaration is not a statement. [Read ECMA-262's note on this issue](http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-262.pdf#page=97). ```javascript // bad @@ -492,7 +492,7 @@ } ``` - - Never name a parameter `arguments`. This will take precedence over the `arguments` object that is given to every function scope. + - [7.5](#7.5) Never name a parameter `arguments`. This will take precedence over the `arguments` object that is given to every function scope. ```javascript // bad @@ -507,7 +507,7 @@ ``` - - Never use `arguments`, opt to use rest syntax `...` instead. + - [7.6](#7.6) Never use `arguments`, opt to use rest syntax `...` instead. > Why? `...` is explicit about which arguments you want pulled. Plus rest arguments are a real Array and not Array-like like `arguments`. @@ -525,7 +525,7 @@ ``` - - Use default parameter syntax rather than mutating function arguments. + - [7.7](#7.7) Use default parameter syntax rather than mutating function arguments. ```javascript // really bad @@ -551,7 +551,7 @@ } ``` - - Avoid side effects with default parameters + - [7.8](#7.8) Avoid side effects with default parameters > Why? They are confusing to reason about. @@ -572,7 +572,7 @@ ## Arrow Functions - - When you must use function expressions (as when passing an anonymous function), use arrow function notation. + - [8.1](#8.1) When you must use function expressions (as when passing an anonymous function), use arrow function notation. > Why? It creates a version of the function that executes in the context of `this`, which is usually what you want, and is a more concise syntax. @@ -590,7 +590,7 @@ }); ``` - - If the function body fits on one line, feel free to omit the braces and use implicit return. Otherwise, add the braces and use a `return` statement. + - [8.2](#8.2) If the function body fits on one line, feel free to omit the braces and use implicit return. Otherwise, add the braces and use a `return` statement. > Why? Syntactic sugar. It reads well when multiple functions are chained together. @@ -606,7 +606,7 @@ }); ``` - - Always use parentheses around the arguments. Omitting the parentheses makes the functions less readable and only works for single arguments. + - [8.3](#8.3) Always use parentheses around the arguments. Omitting the parentheses makes the functions less readable and only works for single arguments. > Why? These declarations read better with parentheses. They are also required when you have multiple parameters so this enforces consistency. @@ -623,7 +623,7 @@ ## Constructors - - Always use `class`. Avoid manipulating `prototype` directly. + - [9.1](#9.1) Always use `class`. Avoid manipulating `prototype` directly. > Why? `class` syntax is more concise and easier to reason about. @@ -652,7 +652,7 @@ } ``` - - Use `extends` for inheritance. + - [9.2](#9.2) Use `extends` for inheritance. > Why? It is a built-in way to inherit prototype functionality without breaking `instanceof`. @@ -675,7 +675,7 @@ } ``` - - Methods can return `this` to help with method chaining. + - [9.3](#9.3) Methods can return `this` to help with method chaining. ```javascript // bad @@ -712,7 +712,7 @@ ``` - - It's okay to write a custom toString() method, just make sure it works successfully and causes no side effects. + - [9.4](#9.4) It's okay to write a custom toString() method, just make sure it works successfully and causes no side effects. ```javascript class Jedi { @@ -735,7 +735,7 @@ ## Modules - - Always use modules (`import`/`export`) over a non-standard module system. You can always transpile to your preferred module system. + - [10.1](#10.1) Always use modules (`import`/`export`) over a non-standard module system. You can always transpile to your preferred module system. > Why? Modules are the future, let's start using the future now. @@ -753,7 +753,7 @@ export default es6; ``` - - Do not use wildcard imports. + - [10.2](#10.2) Do not use wildcard imports. > Why? This makes sure you have a single default export. @@ -765,7 +765,7 @@ import AirbnbStyleGuide from './AirbnbStyleGuide'; ``` - - And do not export directly from an import. + - [10.3](#10.3) And do not export directly from an import. > Why? Although the one-liner is concise, having one clear way to import and one clear way to export makes things consistent. @@ -784,7 +784,7 @@ ## Iterators and Generators - - Don't use iterators. Prefer JavaScript's higher-order functions like `map()` and `reduce()` instead of loops like `for-of`. + - [11.1](#11.1) Don't use iterators. Prefer JavaScript's higher-order functions like `map()` and `reduce()` instead of loops like `for-of`. > Why? This enforces our immutable rule. Dealing with pure functions that return values is easier to reason about than side-effects. @@ -809,7 +809,7 @@ sum === 15; ``` - - Don't use generators for now. + - [11.2](#11.2) Don't use generators for now. > Why? They don't transpile well to ES5. @@ -818,7 +818,7 @@ ## Properties - - Use dot notation when accessing properties. + - [12.1](#12.1) Use dot notation when accessing properties. ```javascript const luke = { @@ -833,7 +833,7 @@ const isJedi = luke.jedi; ``` - - Use subscript notation `[]` when accessing properties with a variable. + - [12.2](#12.2) Use subscript notation `[]` when accessing properties with a variable. ```javascript const luke = { @@ -853,7 +853,7 @@ ## Variables - - Always use `const` 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. + - [13.1](#13.1) Always use `const` 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. ```javascript // bad @@ -863,7 +863,7 @@ const superPower = new SuperPower(); ``` - - Use one `const` declaration per variable. + - [13.2](#13.2) Use one `const` declaration per variable. > Why? It's easier to add new variable declarations this way, and you never have to worry about swapping out a `;` for a `,` or introducing punctuation-only diffs. @@ -885,7 +885,7 @@ const dragonball = 'z'; ``` - - Group all your `const`s and then group all your `let`s. + - [13.3](#13.3) Group all your `const`s and then group all your `let`s. > Why? This is helpful when later on you might need to assign a variable depending on one of the previous assigned variables. @@ -910,7 +910,7 @@ let length; ``` - - Assign variables where you need them, but place them in a reasonable place. + - [13.4](#13.4) Assign variables where you need them, but place them in a reasonable place. > Why? `let` and `const` are block scoped and not function scoped. @@ -962,7 +962,7 @@ ## Hoisting - - `var` declarations get hoisted to the top of their scope, their assignment does not. `const` and `let` declarations are blessed with a new concept called [Temporal Dead Zones (TDZ)](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/let#Temporal_dead_zone_and_errors_with_let). It's important to know why [typeof is no longer safe](http://es-discourse.com/t/why-typeof-is-no-longer-safe/15). + - [14.1](#14.1) `var` declarations get hoisted to the top of their scope, their assignment does not. `const` and `let` declarations are blessed with a new concept called [Temporal Dead Zones (TDZ)](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/let#Temporal_dead_zone_and_errors_with_let). It's important to know why [typeof is no longer safe](http://es-discourse.com/t/why-typeof-is-no-longer-safe/15). ```javascript // we know this wouldn't work (assuming there @@ -997,7 +997,7 @@ } ``` - - Anonymous function expressions hoist their variable name, but not the function assignment. + - [14.2](#14.2) Anonymous function expressions hoist their variable name, but not the function assignment. ```javascript function example() { @@ -1011,7 +1011,7 @@ } ``` - - Named function expressions hoist the variable name, not the function name or the function body. + - [14.3](#14.3) Named function expressions hoist the variable name, not the function name or the function body. ```javascript function example() { @@ -1039,7 +1039,7 @@ } ``` - - Function declarations hoist their name and the function body. + - [14.4](#14.4) Function declarations hoist their name and the function body. ```javascript function example() { @@ -1058,8 +1058,8 @@ ## Comparison Operators & Equality - - Use `===` and `!==` over `==` and `!=`. - - Conditional statements such as the `if` statement evaulate their expression using coercion with the `ToBoolean` abstract method and always follow these simple rules: + - [15.1](#15.1) Use `===` and `!==` over `==` and `!=`. + - [15.2](#15.2) Conditional statements such as the `if` statement evaulate their expression using coercion with the `ToBoolean` abstract method and always follow these simple rules: + **Objects** evaluate to **true** + **Undefined** evaluates to **false** @@ -1075,7 +1075,7 @@ } ``` - - Use shortcuts. + - [15.3](#15.3) Use shortcuts. ```javascript // bad @@ -1099,14 +1099,14 @@ } ``` - - For more information see [Truth Equality and JavaScript](http://javascriptweblog.wordpress.com/2011/02/07/truth-equality-and-javascript/#more-2108) by Angus Croll. + - [15.4](#15.4) For more information see [Truth Equality and JavaScript](http://javascriptweblog.wordpress.com/2011/02/07/truth-equality-and-javascript/#more-2108) by Angus Croll. **[⬆ back to top](#table-of-contents)** ## Blocks - - Use braces with all multi-line blocks. + - [16.1](#16.1) Use braces with all multi-line blocks. ```javascript // bad @@ -1130,7 +1130,7 @@ } ``` - - If you're using multi-line blocks with `if` and `else`, put `else` on the same line as your + - [16.2](#16.2) If you're using multi-line blocks with `if` and `else`, put `else` on the same line as your `if` block's closing brace. ```javascript @@ -1158,7 +1158,7 @@ ## Comments - - Use `/** ... */` for multi-line comments. Include a description, specify types and values for all parameters and return values. + - [17.1](#17.1) Use `/** ... */` for multi-line comments. Include a description, specify types and values for all parameters and return values. ```javascript // bad @@ -1190,7 +1190,7 @@ } ``` - - Use `//` for single line comments. Place single line comments on a newline above the subject of the comment. Put an empty line before the comment. + - [17.2](#17.2) Use `//` for single line comments. Place single line comments on a newline above the subject of the comment. Put an empty line before the comment. ```javascript // bad @@ -1220,9 +1220,9 @@ } ``` - - 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`. + - [17.3](#17.3) 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`. - - Use `// FIXME:` to annotate problems. + - [17.4](#17.4) Use `// FIXME:` to annotate problems. ```javascript class Calculator { @@ -1233,7 +1233,7 @@ } ``` - - Use `// TODO:` to annotate solutions to problems. + - [17.5](#17.5) Use `// TODO:` to annotate solutions to problems. ```javascript class Calculator { @@ -1249,7 +1249,7 @@ ## Whitespace - - Use soft tabs set to 2 spaces. + - [18.1](#18.1) Use soft tabs set to 2 spaces. ```javascript // bad @@ -1268,7 +1268,7 @@ } ``` - - Place 1 space before the leading brace. + - [18.2](#18.2) Place 1 space before the leading brace. ```javascript // bad @@ -1294,7 +1294,7 @@ }); ``` - - Place 1 space before the opening parenthesis in control statements (`if`, `while` etc.). Place no space before the argument list in function calls and declarations. + - [18.3](#18.3) Place 1 space before the opening parenthesis in control statements (`if`, `while` etc.). Place no space before the argument list in function calls and declarations. ```javascript // bad @@ -1318,7 +1318,7 @@ } ``` - - Set off operators with spaces. + - [18.4](#18.4) Set off operators with spaces. ```javascript // bad @@ -1328,7 +1328,7 @@ const x = y + 5; ``` - - End files with a single newline character. + - [18.5](#18.5) End files with a single newline character. ```javascript // bad @@ -1352,7 +1352,7 @@ })(this);↵ ``` - - Use indentation when making long method chains. Use a leading dot, which + - [18.5](#18.5) Use indentation when making long method chains. Use a leading dot, which emphasizes that the line is a method call, not a new statement. ```javascript @@ -1392,7 +1392,7 @@ .call(tron.led); ``` - - Leave a blank line after blocks and before the next statement + - [18.6](#18.6) Leave a blank line after blocks and before the next statement ```javascript // bad @@ -1434,7 +1434,7 @@ ## Commas - - Leading commas: **Nope.** + - [19.1](#19.1) Leading commas: **Nope.** ```javascript // bad @@ -1468,7 +1468,7 @@ }; ``` - - Additional trailing comma: **Yup.** + - [19.2](#19.2) Additional trailing comma: **Yup.** > Why? This leads to cleaner git diffs. Also, transpilers like Babel will remove the additional trailing comma in the transpiled code which means you don't have to worry about the [trailing comma problem](es5/README.md#commas) in legacy browsers. @@ -1516,7 +1516,7 @@ ## Semicolons - - **Yup.** + - [20.1](#20.1) **Yup.** ```javascript // bad @@ -1545,8 +1545,8 @@ ## Type Casting & Coercion - - Perform type coercion at the beginning of the statement. - - Strings: + - [21.1](#21.1) Perform type coercion at the beginning of the statement. + - [21.2](#21.2) Strings: ```javascript // => this.reviewScore = 9; @@ -1558,7 +1558,7 @@ const totalScore = String(this.reviewScore); ``` - - Use `parseInt` for Numbers and always with a radix for type casting. + - [21.3](#21.3) Use `parseInt` for Numbers and always with a radix for type casting. ```javascript const inputValue = '4'; @@ -1582,7 +1582,7 @@ const val = parseInt(inputValue, 10); ``` - - If for whatever reason you are doing something wild and `parseInt` is your bottleneck and need to use Bitshift for [performance reasons](http://jsperf.com/coercion-vs-casting/3), leave a comment explaining why and what you're doing. + - [21.4](#21.4) If for whatever reason you are doing something wild and `parseInt` is your bottleneck and need to use Bitshift for [performance reasons](http://jsperf.com/coercion-vs-casting/3), leave a comment explaining why and what you're doing. ```javascript // good @@ -1594,7 +1594,7 @@ const val = inputValue >> 0; ``` - - **Note:** Be careful when using bitshift operations. Numbers are represented as [64-bit values](http://es5.github.io/#x4.3.19), but Bitshift operations always return a 32-bit integer ([source](http://es5.github.io/#x11.7)). Bitshift can lead to unexpected behavior for integer values larger than 32 bits. [Discussion](https://github.com/airbnb/javascript/issues/109). Largest signed 32-bit Int is 2,147,483,647: + - [21.5](#21.5) **Note:** Be careful when using bitshift operations. Numbers are represented as [64-bit values](http://es5.github.io/#x4.3.19), but Bitshift operations always return a 32-bit integer ([source](http://es5.github.io/#x11.7)). Bitshift can lead to unexpected behavior for integer values larger than 32 bits. [Discussion](https://github.com/airbnb/javascript/issues/109). Largest signed 32-bit Int is 2,147,483,647: ```javascript 2147483647 >> 0 //=> 2147483647 @@ -1602,7 +1602,7 @@ 2147483649 >> 0 //=> -2147483647 ``` - - Booleans: + - [21.6](#21.6) Booleans: ```javascript const age = 0; @@ -1622,7 +1622,7 @@ ## Naming Conventions - - Avoid single letter names. Be descriptive with your naming. + - [22.1](#22.1) Avoid single letter names. Be descriptive with your naming. ```javascript // bad @@ -1636,7 +1636,7 @@ } ``` - - Use camelCase when naming objects, functions, and instances. + - [22.2](#22.2) Use camelCase when naming objects, functions, and instances. ```javascript // bad @@ -1649,7 +1649,7 @@ function thisIsMyFunction() {} ``` - - Use PascalCase when naming constructors or classes. + - [22.3](#22.3) Use PascalCase when naming constructors or classes. ```javascript // bad @@ -1673,7 +1673,7 @@ }); ``` - - Use a leading underscore `_` when naming private properties. + - [22.4](#22.4) Use a leading underscore `_` when naming private properties. ```javascript // bad @@ -1684,7 +1684,7 @@ this._firstName = 'Panda'; ``` - - Don't save references to `this`. Use arrow functions or Function#bind. + - [22.5](#22.5) Don't save references to `this`. Use arrow functions or Function#bind. ```javascript // bad @@ -1711,7 +1711,7 @@ } ``` - - If your file exports a single class, your filename should be exactly the name of the class. + - [22.6](#22.6) If your file exports a single class, your filename should be exactly the name of the class. ```javascript // file contents class CheckBox { @@ -1730,7 +1730,7 @@ import CheckBox from './CheckBox'; ``` - - Use camelCase when you export-default a function. Your filename should be identical to your function's name. + - [22.7](#22.7) Use camelCase when you export-default a function. Your filename should be identical to your function's name. ```javascript function makeStyleGuide() { @@ -1739,7 +1739,7 @@ export default makeStyleGuide; ``` - - Use PascalCase when you export a singleton / function library / bare object. + - [22.8](#22.8) Use PascalCase when you export a singleton / function library / bare object. ```javascript const AirbnbStyleGuide = { @@ -1756,8 +1756,8 @@ ## Accessors - - Accessor functions for properties are not required. - - If you do make accessor functions use getVal() and setVal('hello'). + - [23.1](#23.1) Accessor functions for properties are not required. + - [23.2](#23.2) If you do make accessor functions use getVal() and setVal('hello'). ```javascript // bad @@ -1773,7 +1773,7 @@ dragon.setAge(25); ``` - - If the property is a boolean, use isVal() or hasVal(). + - [23.3](#23.3) If the property is a boolean, use isVal() or hasVal(). ```javascript // bad @@ -1787,7 +1787,7 @@ } ``` - - It's okay to create get() and set() functions, but be consistent. + - [23.4](#23.4) It's okay to create get() and set() functions, but be consistent. ```javascript class Jedi { @@ -1811,7 +1811,7 @@ ## Events - - When attaching data payloads to events (whether DOM events or something more proprietary like Backbone events), pass a hash instead of a raw value. This allows a subsequent contributor to add more data to the event payload without finding and updating every handler for the event. For example, instead of: + - [24.1](#24.1) When attaching data payloads to events (whether DOM events or something more proprietary like Backbone events), pass a hash instead of a raw value. This allows a subsequent contributor to add more data to the event payload without finding and updating every handler for the event. For example, instead of: ```javascript // bad @@ -1842,7 +1842,7 @@ ## jQuery - - Prefix jQuery object variables with a `$`. + - [25.1](#25.1) Prefix jQuery object variables with a `$`. ```javascript // bad @@ -1852,7 +1852,7 @@ const $sidebar = $('.sidebar'); ``` - - Cache jQuery lookups. + - [25.2](#25.2) Cache jQuery lookups. ```javascript // bad @@ -1879,8 +1879,8 @@ } ``` - - For DOM queries use Cascading `$('.sidebar ul')` or parent > child `$('.sidebar > ul')`. [jsPerf](http://jsperf.com/jquery-find-vs-context-sel/16) - - Use `find` with scoped jQuery object queries. + - [25.3](#25.3) For DOM queries use Cascading `$('.sidebar ul')` or parent > child `$('.sidebar > ul')`. [jsPerf](http://jsperf.com/jquery-find-vs-context-sel/16) + - [25.4](#25.4) Use `find` with scoped jQuery object queries. ```javascript // bad @@ -1904,13 +1904,13 @@ ## ECMAScript 5 Compatibility - - Refer to [Kangax](https://twitter.com/kangax/)'s ES5 [compatibility table](http://kangax.github.com/es5-compat-table/). + - [26.1](#26.1) Refer to [Kangax](https://twitter.com/kangax/)'s ES5 [compatibility table](http://kangax.github.com/es5-compat-table/). **[⬆ back to top](#table-of-contents)** ## ECMAScript 6 Styles -This is a collection of links to the various es6 features. +[27.1](#27.1) This is a collection of links to the various es6 features. 1. [Arrow Functions](#arrow-functions) 1. [Classes](#constructors) @@ -1930,7 +1930,7 @@ This is a collection of links to the various es6 features. ## Testing - - **Yup.** + - [28.1](#28.1) **Yup.** ```javascript function() {