Hi! I'm Nicolas and I'm interested in information visualization, JavaScript and web standards.
I currently work as a Data Visualization Scientist at Twitter. I wrote PhiloGL, the JavaScript InfoVis Toolkit and V8-GL.
I like to see language implementors (or creators in this case) talk about the design challenges or choices they're facing with in the next version of their languages.
In this video Brendan Eich, the creator of JavaScript, talks about the ES 3.1/4/5 thingy and also explains what features will be added to JavaScript in some near future (at least for the ECMA standard).
I'll add a couple of comments about the JS features I liked below the video.
New stuff I liked about the language
Most of the things I liked about the new features of the language are related to Meta-Programming. These new features describe new behaviors in object properties, like getters and setters, but they are also related to object and property mutability, configuration, visibility, etc.
Getters and Setters
Getters and Setters were implemented by B.E. more than nine years ago at mozilla, but a new syntax is introduced in the standard by adding a static function to the Object class.
In this example the defineProperty static method of the Object class adds the length property to the obj object. The get and set methods will be called when accessing or modifying the length property.
Object.getOwnPropertyDescriptor retrieves the property descriptor of the defined property.
Defining Methods and Richer Property Descriptors
The Object.defineProperty method can also be used to define instance methods:
The method does something similar as inject_into or reduce methods do in other languages:
[1,2,3].inject(0,function(a,b){returna+b;});//6
If configurable=true, the property will be enabled for deletion or to be changed in other ways.
You can set a property to be non-enumerable by setting enumerable=false, and it won't be detected in a for in loop (or in any other "prop" in obj expression). This means that for example we could augment Object.prototype with methods without having to iterate through them in a for in loop.
The writable property if setted to false won't allow you to change the value of that property.
Object.create
Still no support is added for classical inheritance patterns (which makes me happy I must confess).
Instead, the differential inheritance pattern gets a function that had (somewhat) been implemented by frameworks like Closure, MooTools and others with the inherits and $merge functions.
Object.create can be used for implementing prototypical inheritance: you can create a new class A that inherits from B by cloning an object and augmenting it with a Properties object. For example:
However, don't forget to instantiate the superclass in your subclass constructor:
varPoint=function(x,y){this.x=x;this.y=y;};Point.prototype.distanceToOrigin=function(){returnMath.sqrt(this.x*this.x+this.y*this.y);};//Complex extends PointvarComplex=function(x,y){Point.call(this,x,y);//call the superclass};Complex.prototype=Object.create(Point.prototype,{add:function(complex){this.x+=complex.x;this.y+=complex.y;}});
Object.preventExtensions, Object.seal, Object.freeze
Mutability is nice but sometimes we need to make our objects immutable for design reasons, for security reasons. These methods change the mutability level of an object.
Object.preventExtensions prevents an object from extending (i.e adding new properties to it). Still the properties it has can be deleted and their value can be changed.
Object.seal does everything Object.preventExtensions does and also sets configurable=false for its properties, so they can't be deleted. The Object properties can be changed though.
Object.freeze makes the object completely immutable. Object.freeze does the same Object.preventExtensions and Object.seal do but also sets writable=false for all object properties.
I hope this was useful to you. There are a lot more interesting language features to come, so you can read the ECMA draft if you're interested in knowing more about this new version.