Angus Croll: ES6 Uncensored
Angus Croll (@angustweets) was speaking at Full Frontal about ES6, these are my notes from his talk.
Switch two variables
[a, b] = [b, a] Destructuring. No third var required.
Find the max in array
Math.max(...array); Spread operator turns array into CSV.
Sum an array
Arrow function and rest operator. [Not sure what either of these are?]
Remove duplicates from an array
[...Set(array)] Set is a new type. Also uses spread operator.
Can use destructuring or generators.
We can use destructuring to replace the
Sum of squares
We have array conprehensions
for (x of array).
We can use arrow functions to assign defaults.
We can use arrow functions and literal shorthand - in an object litteral the key is defaulted to the var name? [Didn't understand the explanation.]
We can pass in defaults as an object arguments.
Negative array indexes
Can use negative array indexes to work from the end of an array.
Proxies allow us to stub out an operator. Proxies are possibly the hardest syntax in ES6.
Null safe property chains
I.E. Don't need to check for every property up the chain of
sale.person.name.last. We can use a proxy to create a recursive proxy chain to work through this.
Where can you use it?
Only by playing with something and making mistakes do we learn. Get a head start on the new stuff.
- Firefox is the best - still has a few niggles.
- Chrome - have to enable a flag but only has a subset.
- node --harmony
kangax.github.io has a compatibility table.
@esdiscuss on twitter is a good place to follow what's going on without getting involved with the mailing list.