mirror of
https://github.com/airbnb/javascript.git
synced 2026-04-25 03:00:19 -04:00
[eslint config] [*] [new] set ecmaVersion to 2017; enable object rest/spread; update babel-preset-airbnb
This commit is contained in:
20
README.md
20
README.md
@@ -293,6 +293,26 @@ Other Style Guides
|
||||
console.log(has.call(object, key));
|
||||
```
|
||||
|
||||
<a name="objects--rest-spread"></a>
|
||||
- [3.10](#objects--rest-spread) Prefer the object spread operator over `Object.assign` to shallow-copy objects. Use the object rest operator to get a new object with certain properties omitted.
|
||||
|
||||
```javascript
|
||||
// very bad
|
||||
const original = { a: 1, b: 2 };
|
||||
const copy = Object.assign(original, { c: 3 }); // this mutates `original` ಠ_ಠ
|
||||
delete copy.a; // so does this
|
||||
|
||||
// bad
|
||||
const original = { a: 1, b: 2 };
|
||||
const copy = Object.assign({}, original, { c: 3 }); // copy => { a: 1, b: 2, c: 3 }
|
||||
|
||||
// good
|
||||
const original = { a: 1, b: 2 };
|
||||
const copy = { ...original, c: 3 }; // copy => { a: 1, b: 2, c: 3 }
|
||||
|
||||
const { a, ...noA } = copy; // noA => { b: 2, c: 3 }
|
||||
```
|
||||
|
||||
**[⬆ back to top](#table-of-contents)**
|
||||
|
||||
## Arrays
|
||||
|
||||
Reference in New Issue
Block a user