• Use the literal syntax for object creation. eslint:

    • Use computed property names when creating objects with dynamic property names.

      ```javascript

      function getKey(k) {
      return a key named ${k};
      }

      // bad
      const obj = {
      id: 5,
      name: ‘San Francisco’,
      };
      obj[getKey(‘enabled’)] = true;

    1. [getKey('enabled')]: true,
    2. };
    3. ```

    • 3.3 Use object method shorthand. eslint:

    • 3.4 Use property value shorthand. eslint:

      1. const lukeSkywalker = 'Luke Skywalker';
      2. // bad
      3. const obj = {
      4. lukeSkywalker: lukeSkywalker,
      5. };
      6. // good
      7. lukeSkywalker,

    • 3.5 Group your shorthand properties at the beginning of your object declaration.

    • Only quote properties that are invalid identifiers. eslint: quote-props

      1. // bad
      2. const bad = {
      3. 'foo': 3,
      4. 'bar': 4,
      5. 'data-blah': 5,
      6. };
      7. // good
      8. const good = {
      9. foo: 3,
      10. bar: 4,
      11. };

    • 3.7 Do not call Object.prototype methods directly, such as hasOwnProperty, , and isPrototypeOf.

      1. // very bad
      2. const original = { a: 1, b: 2 };
      3. const copy = Object.assign(original, { c: 3 }); // this mutates `original` ಠ_ಠ
      4. delete copy.a; // so does this
      5. // bad
      6. const original = { a: 1, b: 2 };
      7. const copy = Object.assign({}, original, { c: 3 }); // copy => { a: 1, b: 2, c: 3 }
      8. // good
      9. const original = { a: 1, b: 2 };
      10. const copy = { ...original, c: 3 }; // copy => { a: 1, b: 2, c: 3 }
      11. const { a, ...noA } = copy; // noA => { b: 2, c: 3 }