revisited
http://slides.com/tuxsudo/esnext
The specification behind JavaScript
Version | Release Year |
---|---|
1 | 1997 |
2 | 1998 |
3 | 1999 |
4 | Never! |
5 | 2009 |
5.1 | 2011 |
6 | 2015 |
7 | 2016 (WIP) |
ES6 and ES2015 are synonymous
They refer to the 6th edition of the ECMAScript
released in 2015.
The technical committee behind the specification
Includes people from:
http://www.ecma-international.org/memento/TC39.htm
https://github.com/tc39
The five-stage process to add features to the spec
https://tc39.github.io/process-document/
Stage # | Stage Name | Summary |
---|---|---|
0 | Strawman | Gather community input |
1 | Proposal | Make the pitch |
2 | Draft | Create formal spec/syntax |
3 | Candidate | Field testing |
4 | Finished | Will be part of ESNext |
var i = 911;
for(var i = 0; i<3; i++) {
console.log(i);
}
console.log("Someone dial " + i);
https://jsbin.com/gaceli/1/edit?js,console
let i = 911;
for(let i = 0; i<3; i++) {
console.log(i);
}
console.log("Someone dial " + i);
https://jsbin.com/cusako/1/edit?js,console
var int = 1,
str = "String",
arr = [1, 2, 3, 4],
obj = {one: 1, two: 2};
int = 2;
console.log(int);
str = "";
console.log(str);
arr.push(5);
console.log(arr);
arr = [];
console.log(arr);
obj.three = 3;
console.log(obj);
obj = {};
console.log(obj);
https://jsbin.com/gatinu/3/edit?js,console
const int = 1;
const str = "String";
const arr = [1, 2, 3, 4];
const obj = {one: 1, two: 2};
int = 2;
console.log(int);
str = "";
console.log(str);
arr.push(5);
console.log(arr);
arr = [];
console.log(arr);
obj.three = 3;
console.log(obj);
obj = {};
console.log(obj);
http://bit.ly/1PIgToS
var name = "simon";
var product = "drawrings";
console.log("hello my name is " + name
+ "\nand I like to make " + product);
const name = "simon";
const product = "drawrings";
console.log(
`hello my name is ${name}
and I like to make ${product}`
);
https://jsbin.com/wegama/2/edit?js,console
var results = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
.map(function(n) {
return n*n;
})
.map(function(n) {
return n/2;
})
.filter(function(n) {
return n%1===0;
})
.reduce(function(last, curr) {
return last + curr;
}, 0);
https://jsbin.com/qidawah/5/edit?js,console
const results = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
.map(n => n*n)
.map(n => n/2)
.filter(n => n%1===0)
.reduce((last, curr) => last + curr, 0);
https://jsbin.com/yavema/1/edit?js,console
var stack1 = {
friends: ['bruce', 'matt', 'cory'],
traitor: 'cory',
friendsNotTraitors: function() {
var that = this;
return this.friends.filter(
function(t) {
return that.traitor!==t;
}
);
}
};
var stack2 = {
friends: ['bruce', 'matt', 'cory'],
traitor: 'cory',
friendsNotTraitors: function() {
return this.friends.filter(
function(t) {
return this.traitor!==t;
}.bind(this)
);
}
};
or
https://jsbin.com/fofivu/3/edit?js,console
stack1.friendsNotTraitors();
stack2.friendsNotTraitors();
const stack = {
friends: ['bruce', 'matt', 'cory'],
traitor: 'cory',
friendsNotTraitors: function() {
return this.friends.filter(t => this.traitor!==t);
}
};
stack.friendsNotTraitors();
https://jsbin.com/zasiqo/1/edit?js,console
var toppings = ["pepperoni", "olives"],
size = 12,
time = 60*30;
module.exports = {
toppings: toppings,
size: size,
time: time
};
const toppings = ["pepperoni", "olives"];
const size = 12;
const time = 60*30;
export default { toppings, size, time };
{
onClick: function() {
console.log('i clicked');
}
};
{
onClick() {
console.log('i clicked');
}
};
var name = "Jared",
obj = {};
obj[name] = "Anderson";
const name = "Jared"
const obj = {
[name]: "Anderson"
}
http://bit.ly/1SCiX6p
var arr = ["zero", "one", "two", "three"];
var one = arr[1];
var three = arr[3];
const arr = ["zero", "one", "two", "three"];
const [, one, , three] = arr;
https://jsbin.com/balolaj/2/edit?js,console
var obj = {
zero: 0,
one: 1,
two: 2,
three: 3,
four: 4,
five: 5,
six: 6,
seven: 7,
eight: 8,
nine: 9
};
var one = obj.one;
var three = obj.three;
var five = obj.five;
var seven = obj.seven;
const obj = {
zero: 0,
one: 1,
two: 2,
three: 3,
four: 4,
five: 5,
six: 6,
seven: 7,
eight: 8,
nine: 9
};
const {one, three, five, seven} = obj;
const obj = {
zero: 0,
one: 1,
two: 2,
three: 3,
four: 4,
five: 5,
six: 6,
seven: 7,
eight: 8,
nine: 9
};
const {
one: uno,
three: tres,
five: cinco,
seven: siete
} = obj;
https://jsbin.com/cicica/1/edit?js,console
var obj = {
one: {
eng: "one",
spa: "uno",
int: 1
},
two: {
eng: "two",
spa: "dos",
int: 2
}
};
var spanish1 = obj.one.spa;
var num2 = obj.two.int;
const obj = {
one: {
eng: "one",
spa: "uno",
int: 1
},
two: {
eng: "two",
spa: "dos",
int: 2
}
};
const {
one: {spa: spanish1},
two: {int: num2}
} = obj;
https://jsbin.com/satagi/1/edit?js,console
function errMsg(err) {
return "hey "
+ err.recipient
+ ", something "
+ err.severity + " happened."
+ "\nThe message we got is: '"
+ err.message
+ "'\nThe details are: '"
+ err.details
+ "'";
}
const errMsg = ({recipient, severity, message, details}) =>
`hey ${recipient}, something ${severity} happened.
The message we got is: '${message}'
The details are: '${details}'`;
function sayHi({person: p, mood: m}) {
console.log(`hi ${p}. why so ${m}?`);
}
https://jsbin.com/yupaca/1/edit?js,console
function annoyParents(wheelsArg, round1Arg, round2Arg) {
var wheels = wheelsArg || "wheels";
var round1 = round1Arg || "round";
var round2 = round2Arg || "round";
var roundAndRound = " " + round1 + " and " + round2;
return "The "
+ wheels
+ " on the bus go"
+ roundAndRound.repeat(3)
+ ".\nthe "
+ wheels
+ " on the bus go"
+ roundAndRound
+ " - all through the town.";
}
function annoyParents(wheels="wheels", round1="round", round2="round") {
const roundAndRound = ` ${round1} and ${round2}`;
return `The ${wheels} on the bus go\
${roundAndRound.repeat(3)}. \
The ${wheels} on the bus go\
${roundAndRound} - all through the town.`;
}
https://jsbin.com/fuyixa/1/edit?js,console
function annoyParents({wheels="wheels", round1="round", round2="round"}) {
const roundAndRound = ` ${round1} and ${round2}`;
return `The ${wheels} on the bus go\
${roundAndRound.repeat(3)}. \
The ${wheels} on the bus go\
${roundAndRound} - all through the town.`;
}
https://jsbin.com/fotixu/1/edit?js,console
function annoyParents({
wheels="wheels",
round1="round",
round2="round"
} = {}
) {
const roundAndRound = ` ${round1} and ${round2}`;
return `The ${wheels} on the bus go\
${roundAndRound.repeat(3)}. \
The ${wheels} on the bus go\
${roundAndRound} - all through the town.`;
}
https://jsbin.com/yimiqu/1/edit?js,console
var argsFromSomewhere = [25, 50, 25];
function add3Numbers(a, b, c) {
return a + b + c;
}
add3Numbers.apply(null, argsFromSomewhere);
var argsFromSomewhere = [25, 50, 25];
function add3Numbers(a, b, c) {
return a + b + c;
}
add3Numbers(...argsFromSomewhere);
https://jsbin.com/duyime/1/edit?js,console
var obj1 = { one: 1, two: 2, three: 2};
var obj2 = { three: 3, four: 4, five: 5};
// The ES6 Way
var combined = Object.assign({}, obj1, obj2);
// most common solution:
// pull in library to merge
// jq
var combined = $.extend({}, obj1, obj2);
// underscore
var combined = _.extend({}, obj1, obj2);
const obj1 = { one: 1, two: 2, three: 2};
const obj2 = { three: 3, four: 4, five: 5};
const combined = {...obj1, ...obj2};
http://bit.ly/22Vy7w4
Create a pipeline function that:
pipeline(x, fn1, fn2, fn3, fn4, fn5)
function pipeline () {
var val = arguments[0],
fns = Array.prototype.slice.call(arguments, 1);
return fns.reduce( function(l, c) {
return c(l);
}, val);
}
const pipeline = (val, ...fns) =>
fns.reduce( (l, c) => c(l), val);
https://jsbin.com/tifacip/1/edit?js,console
var myUniqueKey = "___uniqueish_via_obfuscation__FTL___";
const key = Symbol("my-key");
https://jsbin.com/cakoxa/1/edit?js,console
// Global variables
window.globalVar = "ew";
// CommonJS+Browserify
module.exports = {}
require('something');
// SystemJS
System.import('main.js');
export const a = "apple";
export function isCool({ likes = [] }) {
return likes.includes('pizza');
}
export default {
one: 1,
three: 3
};
import {a, isCool} from 'a.js';
import whateverNameIWant from 'a.js';
https://babeljs.io/docs/learn-es2015/
https://github.com/tc39/ecma262
http://kangax.github.io/compat-table/esnext/
http://kangax.github.io/compat-table/es6/
https://hacks.mozilla.org/category/es6-in-depth/