let a = [1, 2, 3];
let max = Math.max(...a);
let a = [1, 2, 3, 4, 5];
let [first, second, ...rest] = a;
let someNumbers = [1, 2, 3];
let moreNumbers = [5, 6];
let allNumbers = someNumbers.concat(4, moreNumbers, 7, 8);
let copy = allNumbers.slice();
let max = copy[0];
copy.forEach(a => max = Math.max(a, max));
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.
let sum = a => a.reduce((b, c) => b + c);
let mySum = sum(a, b, c);
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;
typo on "Invoking variadic functions" section. After example, should readlet max = Math.max(...copy);
--
--
Chromium Developers mailing list: chromi...@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.
let sum = (...a) => a.reduce((b, c) => b + c);
// Original example
let sum = a => a.reduce((b, c) => b + c);
let mySum = sum(a, b, c);
// With spread syntax
let sum = (...a) => a.reduce((b, c) => b + c);
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'};
people.forEach(person => {
processFirstName(person.name.first);
processLastName(person.name.last);
processAge(person.age);
processFull(`${person.name.first} ${person.name.last}`, person.age);
});
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);
});
people.forEach(({name: {first, last}, age}) => {
processFirstName(first);
processLastName(last);
processAge(age);
processFull(`${first} ${last}`, age);
});
// unclear what the parameter `settings` should look like without looking at sample invocations.
function updatePage(settings) {};
function updatePage({bgColor, fontColor, fontSize}) {};
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], '.');
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, '.');
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, '.');
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]
--
--
Chromium Developers mailing list: chromi...@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 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.
--
--
Chromium Developers mailing list: chromi...@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 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.
let sum = (...a) => a.reduce((b, c) => b + c);
let mySum = sum(a, b, c);
--
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.On Mon, Nov 26, 2018 at 2:00 PM manukh via Chromium-dev <chromi...@chromium.org> wrote:
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.
On Tue, Nov 27, 2018 at 10:36 PM Mike Frysinger <vap...@chromium.org> wrote: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.On Mon, Nov 26, 2018 at 2:00 PM manukh via Chromium-dev <chromi...@chromium.org> wrote: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?
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/chromium-dev/CAL95s%2BWxZsU4O9kV3sPOoyaVAFzCRFVaEBU5K7meYNuN-WUqtw%40mail.gmail.com.
--
--
Chromium Developers mailing list: chromi...@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 view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/chromium-dev/CAPUSrA1Myy9EBRUHJRK8jocmSEGNNqyhKd%2BAz7msU0c6FDZQXw%40mail.gmail.com.
It's also tripping the presubmit script:/b/swarming/w/ir/cache/builder/chromium_presubmit/src/chrome/browser/resources/settings/autofill_page/autofill_section.js 173:62 error Parsing error: Unexpected token .. ✖ 1 problem (1 error, 0 warnings)
On Thu, Jan 31, 2019 at 1:43 PM Giovanni Ortuño <ort...@chromium.org> wrote:It's also tripping the presubmit script:/b/swarming/w/ir/cache/builder/chromium_presubmit/src/chrome/browser/resources/settings/autofill_page/autofill_section.js 173:62 error Parsing error: Unexpected token .. ✖ 1 problem (1 error, 0 warnings)There's probably two separate bugs here (since two separate tools are breaking). Could you file a bug for this?
On Fri, Feb 1, 2019 at 5:08 AM Demetrios Papadopoulos <dpa...@chromium.org> wrote:The error is thrown from polymer-bundler, not from Closure compiler. So it is possible that polymer-bundler is failing when that syntax is used. Pasting belowpython ../../chrome/browser/resources/optimize_webui.py --host settings --input gen/chrome/browser/resources/settings/settings_resources.unpak --out_folder gen/chrome/browser/resources/settings --depfile gen/chrome/browser/resources/settings/build.d --html_in_files settings.html lazy_load.html --html_out_files vulcanized.html lazy_load.vulcanized.html --html_out_files_polymer2 vulcanized.p2.html lazy_load.vulcanized.p2.html --js_out_files crisper.js lazy_load.crisper.js --insert_in_head \<base\ href=\"chrome://settings\"\> Traceback (most recent call last): File "../../chrome/browser/resources/optimize_webui.py", line 266, in <module> main(sys.argv[1:]) File "../../chrome/browser/resources/optimize_webui.py", line 260, in main '\n'.join(manifest['_missing'])) Exception: polymer-bundler could not find files for the following URLs: autofill_page/autofill_section.jsThis needs further investigation to come up with a minimal repro example.On Thu, Jan 31, 2019 at 8:14 AM <man...@google.com> wrote:The spread operator for objects is new to ecma 2018 [1]. Additionally, it may also not be supported by iOS 10 (for reference, the rest parameter during object destructuring isn't supported by iOS 10).If you set the closure language_in to ECMASCRIPT_2018 [2], closure will accept the spread operator in objects; though, doing this will also make closure throw other errors and warnings.For reference, there's been discussions about the similar rest parameter during object destructuring [3].