Skip to content

Commit

Permalink
ES6 styleguide: Allow usage of destructuring assignment.
Browse files Browse the repository at this point in the history
Change-Id: I7d710dc1964ac10bcca6a71d9f45c21e8fbbf96e
Reviewed-on: https://chromium-review.googlesource.com/c/1398390
Commit-Queue: manuk hovanesian <manukh@chromium.org>
Reviewed-by: Dan Beam <dbeam@chromium.org>
Cr-Commit-Position: refs/heads/master@{#623427}
  • Loading branch information
manuk authored and Commit Bot committed Jan 16, 2019
1 parent edd6707 commit e1e1aec
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,7 @@ Polymer({
pairs.push([R.SITE_SETTINGS_PAYMENT_HANDLER, 'paymentHandler']);
}

pairs.forEach(pair => {
const route = pair[0];
const id = pair[1];
pairs.forEach(([route, id]) => {
this.focusConfig.set(route.path, () => this.async(() => {
cr.ui.focusWithoutInk(assert(this.$$(`#${id}`)));
}));
Expand Down
89 changes: 51 additions & 38 deletions styleguide/web/es.md
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,57 @@ usesRestParams('a', 'b', 1, 2, 3);
---
### Destructuring Assignment
Flexible destructuring of collections or parameters.
**Usage Example:**
```js
// Array
const [a, , b] = [1, 2, 3]; // a = 1, b = 3
// Object
const {width, height} = document.body.getBoundingClientRect();
// width = rect.width, height = rect.height
// Parameters
function f([name, val]) {
console.log(name, val); // 'bar', 42
}
f(['bar', 42, 'extra 1', 'extra 2']); // 'extra 1' and 'extra 2' are ignored.
function g({name: n, val: v}) {
console.log(n, v); // 'foo', 7
}
g({name: 'foo', val: 7});
function h({name, val}) {
console.log(name, val); // 'bar', 42
}
h({name: 'bar', val: 42});
```
**Mixing with [Rest Parameters](#rest-parameters)**
Using rest parameters while destructuring objects is not supported by iOS 10 and requires setting the closure arg `language_in` to `ECMASCRIPT_2018`.
```js
const {one, ...rest} = {one: 1, two: 2, three: 3};
```
Using rest parameters while destructuring arrays, on the other hand, is supported by iOS 10 and `ECMASCRIPT_2017`.
```js
const [one, ...rest] = [1, 2, 3];
```
**Documentation:** [link](http://www.ecma-international.org/ecma-262/6.0/#sec-destructuring-assignment)
**Discussion Notes / Link to Thread:** [link](https://groups.google.com/a/chromium.org/d/topic/chromium-dev/mwFnj7MTzgU)
---
## Banned Features
The following features are banned for Chromium development.
Expand Down Expand Up @@ -680,44 +731,6 @@ result === 'yy' && re.lastIndex === 5; // true
---
### Destructuring Assignment
Flexible destructuring of collections or parameters.
**Usage Example:**
```js
// Array
const [a, , b] = [1, 2, 3]; // a = 1, b = 3
// Object
const {width, height} = document.body.getBoundingClientRect();
// width = rect.width, height = rect.height
// Parameters
function f([name, val]) {
console.log(name, val); // 'bar', 42
}
f(['bar', 42, 'extra 1', 'extra 2']); // 'extra 1' and 'extra 2' are ignored.
function g({name: n, val: v}) {
console.log(n, v); // 'foo', 7
}
g({name: 'foo', val: 7});
function h({name, val}) {
console.log(name, val); // 'bar', 42
}
h({name: 'bar', val: 42});
```
**Documentation:** [link](https://tc39.github.io/ecma262/#sec-destructuring-assignment)
**Discussion Notes / Link to Thread:**
---
### Modules
Support for exporting/importing values from/to modules without global
Expand Down

0 comments on commit e1e1aec

Please sign in to comment.