Daniela Matos de Carvalho
Software Engineer @Dashlane, mother, photographer amateur, former @requirelx organiser, prev @YLDio, @zpx_interactive
@sericaia
Sep 2017
...
ES3 (1999) ES5 (2009) ES6 (2015) ES7 (2016) ES8 (2017)
...
(https://www.w3.org)
...
...
https://github.com/tc39/proposals/blob/master/stage-0-proposals.md
let result = duplicate(multByThree(2));
let result = 2
|> multByThree
|> duplicate;
using pipeline operator:
function addOneWeek(myDate) {
myDate.setDate(myDate.getDate() + 7);
return myDate;
}
var today = new Date();
var oneWeekFromNow = addOneWeek(today);
console.log(`today is ${today.toLocaleString()},
and one week from today will be ${oneWeekFromNow.toLocaleString()}`);
(example kindly copied from https://maggiepint.com/2017/04/11/fixing-javascript-date-web-compatibility-and-reality/)
1
2
3
4
5
6
7
8
9
10
class Counter {
#xValue = 0;
get #x() { return #xValue; }
set #x(value) {
this.#xValue = value;
}
#clicked() {
this.#x++;
}
constructor() {
super();
this.onclick = this.#clicked.bind(this);
}
//...
}
(example adapted from https://github.com/tc39/proposal-private-methods)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
https://babeljs.io/docs/plugins/transform-object-rest-spread/
https://babeljs.io/docs/plugins/preset-stage-3/
// array
let [first, second] = [1, 2];
let [first, second, ...rest] = [1, 2, 3, 4, 5];
// object
let {first, second} = {first: 1, second: 2}
let {first, second, ...rest} = {first: 1, second: 2, third: 3, fourth: 4}
async function getById(id) {
const item = await db.getById(id);
return item;
}
https://babeljs.io/docs/plugins/transform-async-to-generator/
https://babeljs.io/docs/plugins/preset-stage-3/ (will be removed soon)
async function getById(id) {
try {
const item = await db.getById(id);
return item;
} catch(err) {
// deal with it (reject the promise)!
}
}
// some Hapi.js route
server.route({
method: 'GET',
path: '/',
handler: async function (request, reply) {
const {
firstId,
secondId
} = request.params;
const firstItem = await db.getById(firstId);
const secondItem = await db.getById(secondId);
reply({first: firstItem, second: secondItem});
}
});
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
// some Hapi.js route
server.route({
method: 'GET',
path: '/',
handler: async function (request, reply) {
const {
firstId,
secondId
} = request.params;
const [ firstItem, secondItem ] = await Promise.all([
db.getById(firstId),
db.getById(secondId)
]);
reply({ first: firstItem, second: secondItem });
}
});
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
By Daniela Matos de Carvalho
Software Engineer @Dashlane, mother, photographer amateur, former @requirelx organiser, prev @YLDio, @zpx_interactive