ECMAScript 2015:
What Took It So Long?

Allen Wirfs-Brock
Project Editor, ECMAScript 2015 Language Specification@awbjshttp://ecma-international.org/ecma-262/6.0/

What is ECMAScript?
• ECMAScript is the name of theinternational standard that defines theJavaScript programming language• Developed by Technical Committee 39(TC-39) of Ecma International• Issued as a Ecma-262 and ISO/IEC 16262• Not part of W3C
GoogleMozilla
Microsoft
V8 SpiderMonkey ChakraWebkit
JSCoreJavaScript Implementations

• May 1995, Created in ten days by Brendan Eich at Netscape: “Mocha”• September 1995, shipped in beta of Netscape Navigator 2.0: “LiveScript”• December 1995, Netscape 2.0b3: “JavaScript”• August 1996, JavaScript cloned in Microsoft IE 3.0: “JScript”• 1996-1997, Standardization ECMA-262 Ed. 1: ”ECMAScript” aka ES1• 1999, ES3 − modern JS baseline

ECMAScript: Troubled Adolescence• 2000: ES4, attempt 1• 2003-4: E4X, XML extensions for ECMAScript• 2005-7: ES4, attempt 2• 2008: ES4 abandoned• 2009: ES5: “use strict”, JSON, Object.create, etc.

The ECMAScript Standard Timeline“Web 2.0” / AJAX

ES 1 ES 2 ES 3(1997) (1998) (1999)

ES 5 ES 5.1(2009) (2011)JS PerformanceRevolution
“ES4”
E4X
“ES4”

ES 2015“ES6”

First Comprehensive Revision Since 1999
Some ECMAScript 2015 Enhancements• More concise and expressive syntax• Modules• Class Declarations• Block scoped declarations• Control abstraction via iterators and generators• Promises• String interpolation/Internal DSL support• Subclassable built-ins• Binary Array Objects with Array methods• Built-in hash Maps and Sets + weak variants.
• More built-in Math and String functions• Improved Unicode support

ES 2015 (June 2015): 566 pages
ES 5 (Dec. 2009):252 pages
ES 3 (Dec. 1999):
188 pages
ES 2 (Aug 1998):
117 pages
ES 1 (June 1997):
110 pages

TC-39 isn’t like either of these

Things TC-39 focused on for ES 2015
• Modularity• Better Abstraction Capability• Better functional programming support• Better OO Support• Expressiveness and Clarity• Better Compilation Target• Things that nobody else can doWhat Kind of Language Is JavaScript?
• Functional?
• Object-oriented?
• Class-based?
• Prototype-based?
• Permissive?
• Secure?
Photo by crazybarefootpoet @ flickr (CC BY-NC-SA 2.0)

http://www.flickr.com/photos/benledbetter-architect/sets/72157594338948430/

Interconnections

Interactions

The closure in loop problem
function f(x) {for (var p in x) {var v = doSomething(x, p);
obj.addCallback(function(args){handle(v, p, args)});}}…
obj.runCallbacks();

var hoisting causes the problem
function f(x) {var p;
var v;for (var p in x) {var v = doSomething(x, p);obj.setCallback(function(args){handle(v, p, args)});}}…
obj.runCallbacks();

ES6 can’t redefine the scoping of var
function f(x) {for (var p in x) {var v = doSomething(x, p);if (v === somethingSpecial) break;}if (v === somethingSpecial) ...
}Fixing closure in loop problem:
Add a new block scoped declaration
function f(x) {for (var let p in x) {var let v = doSomething(x, p);obj.setCallback(function(args){handle(v, p, args))};}}…
obj.runCallbacks();Other local scoping WTFs
function f(x,x) {var x;for (var x in obj) {if (obj[x] === somethingSpecial) {var x = 0;...
}}function x() { doSomething()}x();}

Want to avoid new let WTFs//duplicate declarations
function f() {let x = 1;
let x = 2;}//duplicate let and parameter
function h(x) {let x = 1;}//duplicate let and function
function h() {let x = 1;function x() {}}//duplicate let and var
function g() {let x = 1;
var x = 2;}//hoist var to/over let
function ff() {let x = 1;
if (pred) {var x;}}

Some ES6 Declaration Rules• Single unique binding for any name in a scope.
• Multiple var and top-level function declarations for the same
name are allowed. (Still one binding per name) Just like ES1-5• All other multiple declarations are errors: var/let, let/let, let/const,class/function, etc.

• var declarations hoist to top level and auto initialized to undefined.
Just like ES1-5• Can’t hoist a var over any other declaration of same name (excepta top-level function, just like ES1-5)• Runtime error, for accessing or assigning to an uninitialized binding• let, const, class declarations are dead until initialized (TDZ).

http://www.robomargo.com/furniture.html

So, What’s Next?
ECMAScript 2030 ?
1132 pages ?

The ECMAScript Standard Timeline
Release trains are now leaving the station

ES 1 ES 2 ES 3
(1997) (1998) (1999)

ES 5 ES 5.1(2009) (2011)

“ES4”
E4X
“ES4”

ESES2015 2016ES2017 …

Annual June
Incremental Updates

Process: https://tc39.github.io/process-document/
Proposals: https://github.com/tc39/ecma262/blob/master/README.md

• It’s real
• The specification is done
• Transpilers and polyfills available
today• It’s being implemented in yourfavorite browers right now• It’s the foundation for the next

10-20 years of JavaScript evolution

http://wirfs-brock.com/allen/files/viewsource-es2015.pdf

Allen Wirfs-Brock
http://www.wirfs-brock.com/allen
allen@wirfs-brock.com@awbjs