manukh via Chromium-dev
2018-11-26 20:43:01 UTC
Proposing to move spread
<https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Spread_syntax>
and rest
<https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/rest_parameters> to
the "allowed features" section of the es style guide
<https://chromium.googlesource.com/chromium/src/+/master/styleguide/web/es.md#Rest-Parameters>
.
*Spread Syntax*
let a = [1, 2, 3];
let max = Math.max(...a);
*Rest Syntax*
let a = [1, 2, 3, 4, 5];
let [first, second, ...rest] = a;
*Benefits*
*Elegant alternative to `concat` concatenating*
Before
let someNumbers = [1, 2, 3];
let moreNumbers = [5, 6];
let allNumbers = someNumbers.concat(4, moreNumbers, 7, 8);
After
let someNumbers = [1, 2, 3];
let moreNumbers = [5, 6];
let allNumbers = [...someNumbers, 4, ...moreNumbers, 7, 8];
*Clearer than .slice when copying*
Before
let copy = allNumbers.slice();
After
let copy = [...allNumbers];
*Invoking variadic functions*
Before
let max = copy[0];
copy.forEach(a => max = Math.max(a, max));
After
let max = Math.max(copy);
*Defining Variadic functions.*
Before
let sum2 = (a, b) => a + b;
let sum3 = (a, b, c) => a + b + c;
let sum4 = (a, b, c, d) => a + b + c + d;
let sum = array => array.reduce((a, b) => a + b);
// or
function sumArguments() {
return arguments.reduce((a, b) => a + b);
}
let mySum = sum3(a, b, c); // problematic when later changed to sum 4
numbers.
After
let sum = a => a.reduce((b, c) => b + c);
let mySum = sum(a, b, c);
*Compatibility:*
Supported by i <https://kangax.github.io/compat-table/es6/>Enter code
here...
OS 10.0-10.2 <https://kangax.github.io/compat-table/es6/>
Works with closure, eslint and clang.
<https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Spread_syntax>
and rest
<https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/rest_parameters> to
the "allowed features" section of the es style guide
<https://chromium.googlesource.com/chromium/src/+/master/styleguide/web/es.md#Rest-Parameters>
.
*Spread Syntax*
let a = [1, 2, 3];
let max = Math.max(...a);
*Rest Syntax*
let a = [1, 2, 3, 4, 5];
let [first, second, ...rest] = a;
*Benefits*
*Elegant alternative to `concat` concatenating*
Before
let someNumbers = [1, 2, 3];
let moreNumbers = [5, 6];
let allNumbers = someNumbers.concat(4, moreNumbers, 7, 8);
After
let someNumbers = [1, 2, 3];
let moreNumbers = [5, 6];
let allNumbers = [...someNumbers, 4, ...moreNumbers, 7, 8];
*Clearer than .slice when copying*
Before
let copy = allNumbers.slice();
After
let copy = [...allNumbers];
*Invoking variadic functions*
Before
let max = copy[0];
copy.forEach(a => max = Math.max(a, max));
After
let max = Math.max(copy);
*Defining Variadic functions.*
Before
let sum2 = (a, b) => a + b;
let sum3 = (a, b, c) => a + b + c;
let sum4 = (a, b, c, d) => a + b + c + d;
let sum = array => array.reduce((a, b) => a + b);
// or
function sumArguments() {
return arguments.reduce((a, b) => a + b);
}
let mySum = sum3(a, b, c); // problematic when later changed to sum 4
numbers.
After
let sum = a => a.reduce((b, c) => b + c);
let mySum = sum(a, b, c);
*Compatibility:*
Supported by i <https://kangax.github.io/compat-table/es6/>Enter code
here...
OS 10.0-10.2 <https://kangax.github.io/compat-table/es6/>
Works with closure, eslint and clang.
--
--
Chromium Developers mailing list: chromium-***@chromium.org
View archives, change email options, or unsubscribe:
http://groups.google.com/a/chromium.org/group/chromium-dev
---
You received this message because you are subscribed to the Google Groups "Chromium-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-dev+***@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/chromium-dev/1acaa96c-14be-49dd-964d-b44f88bca0a0%40chromium.org.
--
Chromium Developers mailing list: chromium-***@chromium.org
View archives, change email options, or unsubscribe:
http://groups.google.com/a/chromium.org/group/chromium-dev
---
You received this message because you are subscribed to the Google Groups "Chromium-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-dev+***@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/chromium-dev/1acaa96c-14be-49dd-964d-b44f88bca0a0%40chromium.org.