Roadmap for ECMAScript.next:
function foo(x, y, ...rest) { this.bar(...rest); }
module SpriteCore { export function Canvas(...) {...} }Or separate file:
export function Canvas(...) {...}Current way of loading a module: callback works with module.
require("lib/SpriteCore.js", function(SpriteCore) { require("lib/jQuery.js", function($) { ... }); });Future way of loading a module: client determines module name, which avoids conflicts and makes module names shorter.
module SpriteCore = "lib/SpriteCore.js"; module $ = "lib/jQuery.js"; import SpriteCore.*; // unqualified importDestructuring:
function Element({width: w, height: h, color: c}) { ... } var [key, val] = find(...);Generators (inspired by Python). A generator-based library helps with callback-heavy code. Given the following code.
XHR.load("x.txt", function(x) { XHR.load("y.txt", function(y) { XHR.load("z.txt", function(z) { // work with x,y,z }, onError); }, onError); }, onError);This can be simplified to:
let task = new Task(function() { try { let x = yield XHR.loadAsync(this, "x.txt"); let y = yield XHR.loadAsync(this, "y.txt"); let z = yield XHR.loadAsync(this, "z.txt"); } catch(e) { ... } }); task.start(); // start cooperative thread
let map = new Map(); map.set(obj, 42); map.get(obj) === 42 let set = new Set(); set.add(obj); set.has(obj) === trueVarious other things:
let Point2D = new StructType({ x: uint32, y: uint32 }); let pt = new Point2D({ x: 0, y: 0 });