8. ECMAScript
⚈ Standard of JavaScript
⚈ ECMA-262, also called ECMAScript
⚈ 1.0, 2.0 published around 1997-1998
⚈ Current Edition: 5.1
http://zh.wikipedia.org/wiki/ECMAScript
9. History
⚈ Browser War
⚈ ES3 most supported
⚈ ES4 abandoned
⚈ ES5 current
⚈ ES6 talking today
1999
2009
2014
31. Arrow Function
var square = (x) => {!
return x * x;!
};!
!
var square2 = x => x * x;
http://mdn.io/arrow
32. Arrow Function
// Empty function body!
var foo = (x) => {}!
!
// Single parameter!
var foo = x => {}!
!
// No parameter!
var foo = () => {}!
!
// More parameters!
var foo = (x, y) => {}
33. Arrow Function
// Single expression!
var foo = (x) => x*x!
!
// Multiple expression!
var foo = (x) => {!
let y = x * x;!
// need return!
return y * x;!
}
34. Arrow Function
⚈ Auto return result of single expression
⚈ Lexical this , like CoffeeScript
43. Class Extends
class People extends Counter {!
constructor(people) {!
this.people = people;!
for (let p in people) {!
this.tick();!
}!
}!
}!
!
var p = new People([1,2,3,4,5]);!
p.count; //5
70. Iterable
ID = {};!
!
ID['@@iterator'] = idMaker;!
//or use Symbol!
ID[Symbol.iterator] = idMaker;!
!
for (id of ID) {!
id;!
//0,1,2,3,4,5!
}
http://people.mozilla.org/~jorendorff/es6-draft.html#table-1
84. ES6 for Web
⚈ Precompile ES6 to ES5
⚈ traceur-compiler
⚈ from Google
⚈ AngularJS 2.0
https://github.com/google/traceur-compiler
85.
86. in Develop
⚈ Need watch and compile when file changes
⚈ Use gulp to watch
⚈ gulp-traceur or es6ify to compile
⚈ https://github.com/othree/es6-skeleton