Changes between Version 14 and Version 15 of WebInspectorCodingStyleGuide
- Timestamp:
- Jul 20, 2015 4:24:01 PM (9 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
WebInspectorCodingStyleGuide
v14 v15 10 10 * Style for object literals is: `{key1: value1, key2: value2}`. 11 11 * Add new lines before and after different tasks performed in the same function. 12 * Else-blocks and Promise `.then()` blocks should share a line with leading } or }). 12 * Else-blocks should share a line with leading } or }). 13 * Long promise chains should place `.then()` blocks on a new line. 13 14 * Calling a constructor with no arguments should have no parenthesis `'()'`. eg. `var map = new Map;` 14 15 * Inline anonymous functions, especially if they don't need a bound `this`-object (using `.bind()`). Example: … … 29 30 30 31 * Consider using [http://people.mozilla.org/~jorendorff/es6-draft.html#sec-keyed-collection `Map` and `Set` collections] instead of plain objects. 31 * Consider using ` rgb()` over hex colors in CSS32 * Consider using `hsla()' over hex or RGB colors in CSS. 32 33 * Use `for..of` syntax when performing small actions on each element. Use `forEach` when the function body is longer. Use a classical for loop when doing index math. 33 34 * When using `forEach` or `map`, supply the `this`-object as the optional second parameter rather than binding it. 34 35 * In promise chains, assign `const instance = this;' and capture a reference to `instance` to avoid noisy calls to Function.prototype.bind(). 35 36 36 37 == Layering and abstractions … … 58 59 * Use `Promise.all()` with `map()` to process an array of asynchronous work in parallel. Use `Promise.all()` with `reduce()` to sequence an array asynchronous work. 59 60 * If a result may be a promise or an actual value, wrap the value in a promise, e.g., `Promise.resolve(val)` 60 * Use `.catch()` at the end of a chain to perform error handling. 61 * Use `.catch()` at the end of a chain to perform error handling. Most promise chains should have a catch block to avoid dropping errors. 61 62 * To reject a promise, throw an `Error` instance or call the `reject` callback with an `Error` instance. 62 63 * A `.catch()` block is considered resolved if it does not re-throw an `Error` instance. Re-throw if you want to log an error message and allow other parts of a chain (i.e, an API client) to handle an error condition. … … 72 73 constructor(param) 73 74 { 74 WebInspector.Object.call(this);75 super(); 75 76 this._propertyName = param; 76 77 }