Java Reference
In-Depth Information
class Superhuman extends Human {
// Superhuman specific properties and methods go here
Note: Syntactic Sugar
Harmony is not implementing anything different from what already exists in
previous versions of ECMAScript in terms of supporting classes. All that's
changing is the notation used to implement them. This is known as syntact-
ic sugar , as it allows us to write an existing piece of code in a nicer, more
succinct way.
Arrow Notation
Harmony will introduce a new arrow notation that can be used as syntactic sugar to write
anonymous callbacks more concisely. For example, the following code uses the map()
method and a callback function to square each value in an array:
[1,2,3].map( function(x) { return x * x } );
This can be written using the arrow notation:
[1,2,3].map(x => x * x);
Instead of needing the function keyword, all that's required is to place the parameters
before the => symbol, followed by the return value of the callback.
The arrow notation also fixes the scope problem associated with the keyword this (dis-
cussed in Chapter 12 ). Any nested functions that are written using the arrow notation will
keep the scope of this .
Default Parameters
Harmony will allow default parameters to be specified in a function definition. This means
that the following workaround that we covered in Chapter 4 using the || operator will be
Search WWH ::

Custom Search