import
export
// export.js
export function foo() {
console.log('foo');
}
export function bar() {
console.log('bar');
}
// import.js
import { foo, bar } from './export.js';
foo();
// => foo
bar();
// => bar
ES6
Slide 20
Slide 20 text
Rest
Parameters
let x = 10, y = 20, z = 30;
function max(array) {
return Math.max.apply(null, array);
}
max([x, y, z]);
// => 30
function max(...array) {
return Math.max.apply(null, array);
}
max(x, y, z);
// => 30
ES6
ES6
let hundred = 100;
let multiple = function (x, y) {
return x * y;
}
console.log(`hundred is ${number}`);
// => hundred is 100
console.log(`hundred * 10 is ${multiple(number, 10)}`);
// => hundred * 10 is 1000
Template
Strings
ES6
Slide 23
Slide 23 text
function Human (message) {
this.message = message;
}
Human.prototype.hello = function () {
console.log(this.message);
}
class Human {
constructor(message) {
this.message = message;
}
hello() {
console.log(this.message);
}
}
Class
ES6
ES5
Set
WeakSet
var set1 = new Set([1, 2, 2, 3, 3, 3, 4, 4, 4, 4]);
// => [1, 2, 3, 4]
var set2 = new Set(set1);
var set3 = new Set(set1.entries());
var set4 = new Set(set1.keys());
ES6
Slide 29
Slide 29 text
Map
WeakMap
var arrayKey = [];
var map = new Map();
map.set(1, 'This is a value');
map.set(arrayKey, 'This is also value');
map.get(1);
// This is a value
map.get(arrayKey);
// This is also value
ES6