Discussion:
[chromium-dev] ES6 in Chromium proposal: spread & rest operators
manukh via Chromium-dev
2018-11-26 20:43:01 UTC
Permalink
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.
--
--
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.
dpapad
2018-11-26 22:24:07 UTC
Permalink
Thanks for starting this thread. FWIW, I had stated a CL to update the
styleguide here
<https://chromium-review.googlesource.com/c/chromium/src/+/1271915> (which
also included destructuring assignment), but did not get to sending a
proposal.
Post by manukh via Chromium-dev
Proposing to move spread
<https://www.google.com/url?q=https%3A%2F%2Fdeveloper.mozilla.org%2Fen-US%2Fdocs%2FWeb%2FJavaScript%2FReference%2FOperators%2FSpread_syntax&sa=D&sntz=1&usg=AFQjCNF-BYfD5SM7sGsTwRFxgIRDhXTqMA>
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;
This example also uses "destructuring assignment" which is a different
feature, and not part of this proposal thread. Should we make it part of
it, so that we don't need a separate thread?
Post by manukh via Chromium-dev
*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://www.google.com/url?q=https%3A%2F%2Fkangax.github.io%2Fcompat-table%2Fes6%2F&sa=D&sntz=1&usg=AFQjCNFc3itF9EyKlQUVhb6WefvfvdnLtQ>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/236f3fcc-47c4-447a-94a6-0c2a7745fe69%40chromium.org.
manukh via Chromium-dev
2018-11-27 15:14:09 UTC
Permalink
typo on "Invoking variadic functions" section. After example, should read

let max = Math.max(...copy);
--
--
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/4e768964-a5d5-472a-80a7-719ea16834e5%40chromium.org.
PhistucK
2018-11-27 17:03:02 UTC
Permalink
The last example seems to have some issues (in the before and the after
does not use this feature).

☆*PhistucK*


On Tue, Nov 27, 2018 at 5:14 PM manukh via Chromium-dev <
Post by manukh via Chromium-dev
typo on "Invoking variadic functions" section. After example, should read
let max = Math.max(...copy);
--
--
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
To view this discussion on the web visit
https://groups.google.com/a/chromium.org/d/msgid/chromium-dev/4e768964-a5d5-472a-80a7-719ea16834e5%40chromium.org
<https://groups.google.com/a/chromium.org/d/msgid/chromium-dev/4e768964-a5d5-472a-80a7-719ea16834e5%40chromium.org?utm_medium=email&utm_source=footer>
.
--
--
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/CABc02_%2B7eMCS0FOUw9nvFJy_cMBSqhkAN6M8FVc7T54TEYT9MQ%40mail.gmail.com.
d***@chromium.org
2018-11-27 15:42:46 UTC
Permalink
Thanks for starting this!

I am a bit confused by the *after* code sample in "Defining Variadic
Functions".

// Original example
let sum = a => a.reduce((b, c) => b + c);
let mySum = sum(a, b, c);

Assuming *a*, *b*, and *c* are numeric, wouldn't *sum(a, b, c)* ignore *b* and
*c*?

I would expect the parameters of *sum* to be defined with the spread
operator, like this.

// With spread syntax
let sum = (...a) => a.reduce((b, c) => b + c);
Post by manukh via Chromium-dev
typo on "Invoking variadic functions" section. After example, should read
let max = Math.max(...copy);
--
--
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/5dfbc5ee-e99e-483f-9c12-20ad0c470376%40chromium.org.
manukh via Chromium-dev
2018-11-27 21:25:31 UTC
Permalink
Yes, you're both correct, the last example (Defining Variadic functions,
after) should be



*let sum = (...a) => a.reduce((b, c) => b + c);let mySum = sum(a, b, c);*
Post by d***@chromium.org
Thanks for starting this!
I am a bit confused by the *after* code sample in "Defining Variadic
Functions".
// Original example
let sum = a => a.reduce((b, c) => b + c);
let mySum = sum(a, b, c);
Assuming *a*, *b*, and *c* are numeric, wouldn't *sum(a, b, c)* ignore *b* and
*c*?
I would expect the parameters of *sum* to be defined with the spread
operator, like this.
// With spread syntax
let sum = (...a) => a.reduce((b, c) => b + c);
Post by manukh via Chromium-dev
typo on "Invoking variadic functions" section. After example, should read
let max = Math.max(...copy);
--
--
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/8946addf-ad68-4094-926e-3b36f491ff2e%40chromium.org.
manukh via Chromium-dev
2018-11-27 17:39:03 UTC
Permalink
another typo, apologies, the "Defining Variadic functions" "after" example
should read




*let sum = (...a) => a.reduce((b, c) => b + c);let mySum = sum(a, b, c);*
--
--
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/8f659342-94b6-4fa5-b3f3-22139a5a5ed6%40chromium.org.
manukh via Chromium-dev
2018-11-27 20:26:19 UTC
Permalink
Also proposing to move destructuring
<https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment>
to the "allowed features" section of the es style guide
<https://chromium.googlesource.com/chromium/src/+/master/styleguide/web/es.md#Destructuring-Assignment>
.

*Syntax*

let [one, two] = [1, 2];
let {ten, eleven} = {ten: 10, eleven: 11};


// skipping
let [one, two, , four] = [1, 2, 3, 4];
let {ten, eleven, thirteen} = {ten: 10, eleven: 11, twelve: 12, thirteen: 13
};


// renaming
let {ten, x: eleven} = {ten: 10, x: 11, twelve: 12};


// unwrapping nested objects
let {wrap: {wrap2: {fifty}}} = {wrap: {wrap2: {fifty: 50}}};


// default values
let [zero = 0, xnull = 0, xfalse = 0] = [undefined, null, false];
let {cats = 0, dogs = 0, firstName = '', lastName = ''} = {dogs: 3,
firstName: 'x'};
let {surname: lastName = ''} = {surname: 'false'};

*Benefits*

*1. Conciseness*

Before

people.forEach(person => {
processFirstName(person.name.first);
processLastName(person.name.last);
processAge(person.age);
processFull(`${person.name.first} ${person.name.last}`, person.age);
});

Or

people.forEach(person => {
let first = person.name.first;
let last = person.name.last;
let age = person.age;
processFirstName(first);
processLastName(last);
processAge(age);
processFull(`${first} ${last}`, age);
});

After

people.forEach(({name: {first, last}, age}) => {
processFirstName(first);
processLastName(last);
processAge(age);
processFull(`${first} ${last}`, age);
});

*2. Explicit function interfaces*

Before

// unclear what the parameter `settings` should look like without looking
at sample invocations.
function updatePage(settings) {};

After

function updatePage({bgColor, fontColor, fontSize}) {};

This issue is mitigated when type annotations are available.

*3. Explicit naming of array items*

Before

let htmlText = '<p>The blue fox ate the moon grass.</p>';
let textRegex = /\>([A-Z]\w+) ((?:\w|\s)*)([.!?])?\</;
let lineMatch = htmlText.match(textRegex);

printLarge(lineMatch[1]);
print(lineMatch[2]);
printOrDefault(lineMatch[3], '.');

Or

let htmlText = '<p>The blue fox ate the moon grass.</p>';
let textRegex = /\>([A-Z]\w+) ((?:\w|\s)*)([.!?])?\</;
let lineMatch = htmlText.match(textRegex);
let firstWord = lineMatch[1];
let remainingSentence = lineMatch[2];
let punctuation = lineMatch[3];

printLarge(firstWord);
print(remainingSentence);;
printOrDefault(punctuation, '.');

After

let htmlText = '<p>The blue fox ate the moon grass.</p>';
let textRegex = /\>([A-Z]\w+) ((?:\w|\s)*)([.!?])?\</;
let [, firstWord, remainingSentence, punctuation] = htmlText.match(textRegex
);


printLarge(firstWord);
print(remainingSentence);
printOrDefault(punctuation, '.');


*With Rest operator*

Worth noting, destructuring and rest operator can be used together.
let [first, second, third, ...honorableMentions] = [0, 1, 2, 3, 4, 5, 6, 7]; //
see [1]
let {president, vicePresident, ...otherImportantPeople} = {president: 0,
vicePresident: 1, depStateSec: 2, depDefenseSec: 3, depTreasurySec: 4} //
see [2]

*Compatibility:*
iOS 10.0-10.2
Works with ceslint, clang, and Closure [see below
[1] Rest operator in array destructuring is not supported by iOS.
[2] Rest operators in object destructuring is supported by iOS 11.1+ and
closure compiler with `ECMASCRIPT8` flag.

*Closure support*

*1. Rest operator in object destructuring.*

As noted above, this requires the `ECMASCRIPT8` flag.

*2. Typed arrays*

The below snippet fails to throw a compiler error.

/** @type number */ let one;
[one] = [false];

Similarly, for default values during array deconstruction, the below does
not throw an error.

/** @type string */ let zero;
/** @type string */ let xnull;
/** @type string */ let xfalse;
[zero = 0, xnull = 0, xfalse = 0] = [undefined, null, false];

But this is a broader issue with typed arrays in general, e.g. the below
also fails to throw an error.

/** @type Array<number> */ let array;
array = [false];

Therefore, I don't think this is an argument against allowing
destructuring, but just something worth mentioning.
--
--
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/16ad0750-9239-4616-84ca-2b5eacb0fa5d%40chromium.org.
Mike Frysinger
2018-11-27 21:13:59 UTC
Permalink
can you do one request per thread ? gmail is garbage at threading which
means the conversation becomes unmanageable.
-mike

On Tue, Nov 27, 2018 at 12:27 PM manukh via Chromium-dev <
Post by manukh via Chromium-dev
Also proposing to move destructuring
<https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment>
to the "allowed features" section of the es style guide
<https://chromium.googlesource.com/chromium/src/+/master/styleguide/web/es.md#Destructuring-Assignment>
.
*Syntax*
let [one, two] = [1, 2];
let {ten, eleven} = {ten: 10, eleven: 11};
// skipping
let [one, two, , four] = [1, 2, 3, 4];
13};
// renaming
let {ten, x: eleven} = {ten: 10, x: 11, twelve: 12};
// unwrapping nested objects
let {wrap: {wrap2: {fifty}}} = {wrap: {wrap2: {fifty: 50}}};
// default values
let [zero = 0, xnull = 0, xfalse = 0] = [undefined, null, false];
let {cats = 0, dogs = 0, firstName = '', lastName = ''} = {dogs: 3,
firstName: 'x'};
let {surname: lastName = ''} = {surname: 'false'};
*Benefits*
*1. Conciseness*
Before
people.forEach(person => {
processFirstName(person.name.first);
processLastName(person.name.last);
processAge(person.age);
processFull(`${person.name.first} ${person.name.last}`, person.age);
});
Or
people.forEach(person => {
let first = person.name.first;
let last = person.name.last;
let age = person.age;
processFirstName(first);
processLastName(last);
processAge(age);
processFull(`${first} ${last}`, age);
});
After
people.forEach(({name: {first, last}, age}) => {
processFirstName(first);
processLastName(last);
processAge(age);
processFull(`${first} ${last}`, age);
});
*2. Explicit function interfaces*
Before
// unclear what the parameter `settings` should look like without looking
at sample invocations.
function updatePage(settings) {};
After
function updatePage({bgColor, fontColor, fontSize}) {};
This issue is mitigated when type annotations are available.
*3. Explicit naming of array items*
Before
let htmlText = '<p>The blue fox ate the moon grass.</p>';
let textRegex = /\>([A-Z]\w+) ((?:\w|\s)*)([.!?])?\</;
let lineMatch = htmlText.match(textRegex);
printLarge(lineMatch[1]);
print(lineMatch[2]);
printOrDefault(lineMatch[3], '.');
Or
let htmlText = '<p>The blue fox ate the moon grass.</p>';
let textRegex = /\>([A-Z]\w+) ((?:\w|\s)*)([.!?])?\</;
let lineMatch = htmlText.match(textRegex);
let firstWord = lineMatch[1];
let remainingSentence = lineMatch[2];
let punctuation = lineMatch[3];
printLarge(firstWord);
print(remainingSentence);;
printOrDefault(punctuation, '.');
After
let htmlText = '<p>The blue fox ate the moon grass.</p>';
let textRegex = /\>([A-Z]\w+) ((?:\w|\s)*)([.!?])?\</;
let [, firstWord, remainingSentence, punctuation] = htmlText.match(
textRegex);
printLarge(firstWord);
print(remainingSentence);
printOrDefault(punctuation, '.');
*With Rest operator*
Worth noting, destructuring and rest operator can be used together.
let [first, second, third, ...honorableMentions] = [0, 1, 2, 3, 4, 5, 6, 7
]; // see [1]
let {president, vicePresident, ...otherImportantPeople} = {president: 0,
vicePresident: 1, depStateSec: 2, depDefenseSec: 3, depTreasurySec: 4} //
see [2]
*Compatibility:*
iOS 10.0-10.2
Works with ceslint, clang, and Closure [see below
[1] Rest operator in array destructuring is not supported by iOS.
[2] Rest operators in object destructuring is supported by iOS 11.1+ and
closure compiler with `ECMASCRIPT8` flag.
*Closure support*
*1. Rest operator in object destructuring.*
As noted above, this requires the `ECMASCRIPT8` flag.
*2. Typed arrays*
The below snippet fails to throw a compiler error.
[one] = [false];
Similarly, for default values during array deconstruction, the below does
not throw an error.
[zero = 0, xnull = 0, xfalse = 0] = [undefined, null, false];
But this is a broader issue with typed arrays in general, e.g. the below
also fails to throw an error.
array = [false];
Therefore, I don't think this is an argument against allowing
destructuring, but just something worth mentioning.
--
--
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 view this discussion on the web visit
https://groups.google.com/a/chromium.org/d/msgid/chromium-dev/16ad0750-9239-4616-84ca-2b5eacb0fa5d%40chromium.org
<https://groups.google.com/a/chromium.org/d/msgid/chromium-dev/16ad0750-9239-4616-84ca-2b5eacb0fa5d%40chromium.org?utm_medium=email&utm_source=footer>
.
--
--
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/CAAbOSc%3DC%3DdTxNjDWXv_6E6BHirozrrpm1YyZ5-ACAWzz2GwDHw%40mail.gmail.com.
Mike Frysinger
2018-11-27 21:16:33 UTC
Permalink
i'm all for spread/rest usage! IE is the only notable platform missing
support, but that shouldn't matter to the Chromium project itself.
-mike

On Mon, Nov 26, 2018 at 2:00 PM manukh via Chromium-dev <
Post by manukh via Chromium-dev
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.
--
--
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 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
<https://groups.google.com/a/chromium.org/d/msgid/chromium-dev/1acaa96c-14be-49dd-964d-b44f88bca0a0%40chromium.org?utm_medium=email&utm_source=footer>
.
--
--
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/CAAbOScn_6BvF0-W77c0aPTLkqL-aCN%3DSuFLz0ZaftpxPFCNRog%40mail.gmail.com.
Mike Frysinger
2018-11-28 06:35:35 UTC
Permalink
hmm, we probably need to explicitly say that spread syntax for
arrays/arguments is OK, but for objects it's still not permitted. the
former is in ES6, but the latter is new to ES2018.

https://github.com/tc39/proposal-object-rest-spread
-mike

On Mon, Nov 26, 2018 at 2:00 PM manukh via Chromium-dev <
Post by manukh via Chromium-dev
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.
--
--
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 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
<https://groups.google.com/a/chromium.org/d/msgid/chromium-dev/1acaa96c-14be-49dd-964d-b44f88bca0a0%40chromium.org?utm_medium=email&utm_source=footer>
.
--
--
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/CAAbOScmV1fJXUaLH0%2BnE9tk3f%2BwJqR-MRH__uz7CSJdhZsEfaQ%40mail.gmail.com.
Dan Beam
2018-12-04 02:23:54 UTC
Permalink
Post by Mike Frysinger
hmm, we probably need to explicitly say that spread syntax for
arrays/arguments is OK, but for objects it's still not permitted. the
former is in ES6, but the latter is new to ES2018.
https://github.com/tc39/proposal-object-rest-spread
-mike
On Mon, Nov 26, 2018 at 2:00 PM manukh via Chromium-dev <
Post by manukh via Chromium-dev
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>
.
I'm generally supportive as well! \o/

Question though: do we have any type of static analysis tool that can
detect trying to spread unspreadable types? As in:

let a = 1;
alert(...a);

Or will we always be forced to find these at run time?

-- Dan
Post by Mike Frysinger
Post by manukh via Chromium-dev
*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.
--
--
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 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
<https://groups.google.com/a/chromium.org/d/msgid/chromium-dev/1acaa96c-14be-49dd-964d-b44f88bca0a0%40chromium.org?utm_medium=email&utm_source=footer>
.
--
--
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 view this discussion on the web visit
https://groups.google.com/a/chromium.org/d/msgid/chromium-dev/CAAbOScmV1fJXUaLH0%2BnE9tk3f%2BwJqR-MRH__uz7CSJdhZsEfaQ%40mail.gmail.com
<https://groups.google.com/a/chromium.org/d/msgid/chromium-dev/CAAbOScmV1fJXUaLH0%2BnE9tk3f%2BwJqR-MRH__uz7CSJdhZsEfaQ%40mail.gmail.com?utm_medium=email&utm_source=footer>
.
--
--
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/CANNW_Qpq%3DN6_%3D4ecrkrZ5GE4t4hO1q_7JaUhtFu6yPQg2JUzgQ%40mail.gmail.com.
Dan Beam
2018-12-04 02:31:35 UTC
Permalink
Post by Dan Beam
Post by Mike Frysinger
hmm, we probably need to explicitly say that spread syntax for
arrays/arguments is OK, but for objects it's still not permitted. the
former is in ES6, but the latter is new to ES2018.
https://github.com/tc39/proposal-object-rest-spread
-mike
On Mon, Nov 26, 2018 at 2:00 PM manukh via Chromium-dev <
Post by manukh via Chromium-dev
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>
.
I'm generally supportive as well! \o/
Question though: do we have any type of static analysis tool that can
let a = 1;
alert(...a);
Or will we always be forced to find these at run time?
In my own testing, the answer seems to be: depends on if we have clear type
info when using Closure compiler. https://imgur.com/a/f6mJy1u

-- Dan
Post by Dan Beam
-- Dan
Post by Mike Frysinger
Post by manukh via Chromium-dev
*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.
--
--
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 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
<https://groups.google.com/a/chromium.org/d/msgid/chromium-dev/1acaa96c-14be-49dd-964d-b44f88bca0a0%40chromium.org?utm_medium=email&utm_source=footer>
.
--
--
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 view this discussion on the web visit
https://groups.google.com/a/chromium.org/d/msgid/chromium-dev/CAAbOScmV1fJXUaLH0%2BnE9tk3f%2BwJqR-MRH__uz7CSJdhZsEfaQ%40mail.gmail.com
<https://groups.google.com/a/chromium.org/d/msgid/chromium-dev/CAAbOScmV1fJXUaLH0%2BnE9tk3f%2BwJqR-MRH__uz7CSJdhZsEfaQ%40mail.gmail.com?utm_medium=email&utm_source=footer>
.
--
--
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/CANNW_Qpn-AdNSV8UnKHYUn%3DoBJ1j6iLi%3DZ%3DmzOTDLd%2BcV5hE5w%40mail.gmail.com.
Loading...