From November 27-29, 2012, the Ecma Technical Committee 39 (TC39, [1]) had another meeting, where decisions were made about ECMAScript.next (the code name for ECMAScript 6 [1]). This blog post summarizes and explains the highlights. It is based on Rick Waldrons excellent notes that he put up on GitHub. There is also a list of all 2ality posts on TC39 meetings.
f instanceof GeneratorFunction f.__proto__ === GeneratorFunction.prototype f.__proto__ === (function *() {}).__proto__
let _id = new PrivateSymbol(); let _log = new PrivateSymbol();However, computed property keys have been revived and will be part of ECMAScript.next. Currently we only have static property keys. In ECMAScript.next, you’ll also be able to write an expression in square brackets and its result will be used as the key. For example:
let logger = { [_id]: "ID2543", [_log](message) { console.log(this[_id]+": "+message); } };You can only access the two properties above if you know the values in _id and _log. They can’t be listed via the usual means (Object.getOwnPropertyNames(), for-in, etc.), either. Computed keys also work in ECMAScript 6 classes [5]:
class LoggerFactory { constructor(id) { this[_id] = id; } [_log](message) { console.log(this[_id]+": "+message); } }The advantage of this approach is that it gives you a lot of freedom, because you can explicitly control who has access to a symbol. The disadvantage is that every private identifier has to be declared in advance, leading to redundancy. TC39 does not rule out adding syntax after ECMAScript 6 to reduce some of that work.
Defining a nested module:
module "foo" { module "bar" { // ... } } // Equivalent: module "foo/bar" { // ... }Importing a nested module:
import "foo/bar" as m;
let s = new Set(); s.add('foo').add('bar');Or even:
let s = new Set().add('foo').add('bar');
myFunc(a, b, ...myArray, c) [a, b, ...myArray, c]Among other things, spread can often be used instead of apply().
var let; let[x] = 5;The second line could be mistaken for a let declaration, because ECMAScript.next will have destructuring assignment. For example:
[x, y] = [y, x]; let [a, b] = computePair(); let [c] = computeSingleElementArray();The following rules will be used for parsing let:
let at the beginning of a statement is a let declaration, but it must be followed by either an identifier, an opening square brace "[" or an opening curly brace "{".This rule does not prevent the above mentioned problem in old code, but TC39 will try and inform people about it, so that hopefully nothing important breaks once this feature appears in browsers. However, the rule does prevent all other problems with using let as a variable name.