Although the work on the JavaScript 2.0 specification has not yet been completed, a review of the new features is already available in
PDF format . The developers hope to finish the specification this fall.
So, some things that will be available to us:
OOPFinally:
/* - JavaScript 1.x */
function Foo() {
this.a = "a";
this.b = "b";
}
var myFoo = new Foo();
/* JavaScript 2.0 */
class Bar {
this.a = "a";
this.b = "b";
}
var myBar = new Bar(); // class instantiation
Type checking at compile time :
JavaScript 2.0 components may require to be compiled in the so-called strict mode. This has many advantages, for example:
- Static type checking
- Check for the existence of referred names
- Comparing two variables of the same type
- Prohibition of assigning new values to constants
Did we say constants? :
/* JavaScript 1.x */
var FOO = 'bar'; // , , ,
/* JavaScript 2.0 */
const FOO = 'bar'; // , !
Redefinition of operators :
Now you can do a lot of very good, and a lot of very bad things. Operators now work as you want.
')
Real namespaces :
In JavaScript 1.0, it was possible to emulate namespaces by stuffing different things into a global object. Despite the fact that this is not a very bad practice, it is not quite the correct use of objects. Now the namespace will have its own separate syntax.
Loadable modules :
Create separate modules that will not be loaded until needed. This has a lot of potential, in addition to optimizing traffic. A more serious plus is that this is a step towards creating structured, reusable code for libraries.
use unit Person "http://mysite/library/classes/Person";
use unit DisplayUtil "http://mysite/library/utils/DisplayUtil";
var bob = new Person();
document.writeln(DisplayUtil.display(bob));
Conclusion :
In the current version of the specification of 40 pages, there are still many tasty things - if you do not make it difficult to read in English. Overall, JavaScript 2.0 promises to be a great improvement for the entire web.