Java Reference
In-Depth Information
What's Next: ECMA6, Harmony
The next version of ECMAScript will be version 6. The code name “Harmony” is used to
describe the features that are likely to appear in either version 6 or 7 of ECMAScript. This
section introduces some of the exciting new features under discussion that will help to make
JavaScript a more powerful and expressive language.
Block Scope
The let and const key words are being introduced as an alternative to using var to de-
clare variables.
let works in a similar way to var , but it has block scope, so the variable will only exist
inside the block it was created in:
if(a < 10) {
var b = 2;
let c = 3;
}
// b exists here, but c doesn't
const works in a similar way, but is used for declaring constant values. Once a value is
declared using const , it cannot be redefined or changed:
const PI = Math.PI;
Most modern browsers already support these keywords, so it's possible to try using them
today.
Classes
Harmony includes a new notation for declaring classes in JavaScript. It actually works in the
background in the same way as creating a constructor function and prototype object, such
as we saw in Chapter 12 , but the syntax has been changed so that it looks more like a clas-
sical language. It is hoped that this will reassure programmers who come from a classical
language background, as they are often confused by the lack of classes in JavaScript.
 
Search WWH ::




Custom Search