Technical Committee 39): the committee evolving JavaScript • ECMAScript: official name of the language • Versions: ECMAScript 5 is short for “ECMAScript Language Specification, Edition 5” • ECMAScript 2015: new official name for ES6 (in preparation for yearly releases in ES7+) • Complicated, because ES6 is already so established • JavaScript: the language, colloquially • ECMAScript Harmony: set of features after ES5 (ES6 and later) 4
Code more portable • Tool support (IDEs, type checkers, …) • Foundation for (longer term): • immutable objects • value objects • traits (similar to mixins) • Subclassing built-ins • Help many newcomers Cons: • Syntax quite different from semantics • Based on constructors, not prototype chains (directly) 8
boring: • Polyfillable parts of standard library (Maps, new String +Array methods, Promises) • Unify community, convenient syntax: • Modules • Classes • Arrow functions: less clutter, lexical this 9
more complicated than ever • Coercion rules for symbols are complicated, probably not worth their benefits • Disconnect between class syntax and class semantics (look like an object, are a function) • Kind-of work-around: treat them at face value 11
(x > MAX) { throw new Error( `At most ${MAX} allowed: ${x}!` // 'At most '+MAX+' allowed: '+x+'!' ); } // Multiple lines let str = `this is a text with multiple lines`; 17
of lines function* splitLines(target) { let previous = ''; try { while (true) { previous += yield; let eolIndex; while ((eolIndex = previous.indexOf('\n')) >= 0) { let line = previous.slice(0, eolIndex); target.next(line); previous = previous.slice(eolIndex+1); } } } finally { // Handle the end of the input sequence // (signaled via `return()`) if (previous.length > 0) { target.next(previous); } // Signal end of output sequence target.return(); } } 24
let tree = new BinaryTree('a', new BinaryTree('b', new BinaryTree('c'), new BinaryTree('d')), new BinaryTree('e')); for (let x of tree) { console.log(x); } // Output: // a // b // c // d // e 30