Changes between Version 14 and Version 15 of WebInspectorCodingStyleGuide

Jul 20, 2015 4:24:01 PM (7 years ago)
Brian Burg

tweaks to style guide


  • WebInspectorCodingStyleGuide

    v14 v15  
    1010* Style for object literals is: `{key1: value1, key2: value2}`.
    1111* 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.
    1314* Calling a constructor with no arguments should have no parenthesis `'()'`. eg. `var map = new Map;`
    1415* Inline anonymous functions, especially if they don't need a bound `this`-object (using `.bind()`). Example:
    3031* Consider using [ `Map` and `Set` collections] instead of plain objects.
    31 * Consider using `rgb()` over hex colors in CSS
     32* Consider using `hsla()' over hex or RGB colors in CSS.
    3233* 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.
    3334* When using `forEach` or `map`, supply the `this`-object as the optional second parameter rather than binding it.
     35* In promise chains, assign `const instance = this;' and capture a reference to `instance` to avoid noisy calls to Function.prototype.bind().
    3637== Layering and abstractions
    5859* 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.
    5960* 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.
    6162* To reject a promise, throw an `Error` instance or call the `reject` callback with an `Error` instance.
    6263* 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.
    7273    constructor(param)
    7374    {
     75       super();
    7576       this._propertyName = param;
    7677    }