ECMAScript 2015/ES6 and node js

Ecmascript (or ES) is a trademarked scripting-language specification standardized by Ecma International in ECMA-262 and ISO/IEC 16262. It was created to standardize JavaScript, so as to foster multiple independent implementations.

The other name for ecmascript 2015 is ES6

Node.js is built against modern versions of V8.

By keeping up-to-date with the latest releases of this engine, we ensure new features from the JavaScript ECMA-262 specification are brought to Node.js developers in a timely manner, as well as continued performance and stability improvements.

All ECMAScript 2015 (ES6) features are split into three groups forshipping,staged, andin progressfeatures:

  1. All shipping features, which V8 considers stable, are turned on by default on Node.js and do NOT require any kind of runtime flag.

  2. Staged features, which are almost-completed features that are not considered stable by the V8 team, require a runtime flag:--harmony

  3. In progress features can be activated individually by their respective harmony flag, although this is highly discouraged unless for testing purposes. Note: these flags are exposed by V8 and will potentially change without any deprecation notice.

ES6 includes the following new features:

Arrows

Arrows are a function shorthand using the => syntax.

They are syntactically similar to the related feature in C#, Java 8 and CoffeeScript. They support both statement block bodies as well as expression bodies which return the value of the expression. Unlike functions, arrows share the same lexical this as their surrounding code.

// Here is an example for an Expression bodies

var odds = evens.map(v => v + 1);

var nums = evens.map((v, i) => v + i);

var pairs = evens.map(v => ({even: v, odd: v + 1}));

// Here is an example for a Statement bodies

nums.forEach(v => {

if (v % 5 === 0)

fives.push(v);

});

// Here is an example for aLexical this

var bob = {

`_name: "Bob",`

`_friends: [],`

`printFriends() {`

     `this._friends.forEach(f =>`

     `console.log(this._name + " knows " + f));`

 `}`

}

More info: MDN Arrow Functions

classes

ES6 classes are a just syntactic sugar over the prototype-based OO pattern.

Having a single convenient declarative form makes class patterns easier to use, and encourages interoperability. Classes support prototype-based inheritance, super calls, instance and static methods and constructors.

class Person {

constructor(height, age) {

this.height = height;

this.age = age;

}

get chestsize() {

return this.calcChestSize();

}

calcChestSize() {

return this.height * 0.23;

}

}

const men = new Person(170, 28);

console.log(men.chestsize);

  • enhanced object literals
  • template strings
  • destructuring
  • default + rest + spread
  • let + const
  • iterators + for..of
  • generators
  • unicode
  • modules
  • module loaders
  • map + set + weakmap + weakset
  • proxies
  • symbols
  • subclassable built-ins
  • promises
  • math + number + string + array + object APIs
  • binary and octal literals
  • reflect api

tail calls

Calls in tail-position are guaranteed to not grow the stack unboundedly.

The stack will not explode and thus Makes recursive algorithms safe in the face of unbounded inputs.

To read more about what is a tail recursion and what we are achiving here

results matching ""

    No results matching ""