On Github MeanMilan / real-life-es6
Was invented by Brendan Eich in May 1995. (in ten days and not in one night)
Has been developed for Netscape
And it has been realesed in Netscape 2 in September.
Became an ECMA standard in 1997.
It is also know as ECMA-262
Some solutions are good
Others are bad
Everybody is going to ship javascript
Allows string literals with embedded expressions in them.
var name = "Matteo"; console.log(`Hello, ${name}!`);Default parameter values allow you to initialize parameters if they were not explicitly supplied. This means that you no longer have to do x = x || {};
var f = function(x = 5){return x + 1};The goal of Arrow Functions is to address and resolve several common pain points of traditional Function Expression:
Rest parameters provide a cleaner way of dealing with functions that takes arbitrary number of parameters than using arguments. Basically your parameters are convertend in an array
var f = function(...args){ var tot = 0; for (var i = 0; i < args.length; i++ ){ tot += args[i]; } return tot/args.length; } f(12, 8, 16, 32); //17The spread construct allows an expression to be expanded in places where multiple arguments are expected
var args = [12, 99, 17] var f = (x, y, z) => Math.min(x, y, z); f(...args);Don't make functions within a loop
var elems = document.getElementsByClassName('myClass'), i; for (i = 0; i < elems.length; i++) { elems[i].addEventListener('click', function () { this.innerHTML = i; }); }The same as let but:
An Iterator is an object that knows how to access items from a collection one at a time, while keeping track of its current position within that sequence
var lang = { name: 'JavaScript', birthYear: 1995 }; var it = Iterator(lang); var pair = it.next(); // Pair is ["name", "JavaScript"] pair = it.next(); // Pair is ["birthYear", 1995] pair = it.next(); // A StopIteration exception is thrown
Works also on arrays, maps, sets..