Home PC Games Linux Windows Database Network Programming Server Mobile  
  Home \ Programming \ Upgrade to Node V4 seven reasons     - Oracle 11g users to create, authorize and import dmp file (Database)

- Using Linux strace command trace / debug a program commonly used options (Linux)

- Arronax allows you to easily create desktop startup file (Linux)

- Mind mapping software installed in CentOS 7 in XMind (Linux)

- How to disable IPv6 on Ubuntu, Linux Mint, Debian (Linux)

- Source code compiled by the installation program under Linux (Linux)

- How to configure AWStats in Ubuntu Server (Server)

- Eclipse installs support for Java 8 (Linux)

- Linux support exFAT and NTFS (Linux)

- The difference between IPython and Python (Linux)

- Access clipboard content across multiple vim instances in a terminal (Linux)

- Oracle 12c detailing the new features (Database)

- Ubuntu 15.10 / 14.04 install subtitling software Aegisub (Linux)

- Ubuntu 15.10 15.04 14.10 14.04 Install Ubuntu Tweak (Linux)

- Linux Change ssh port and disable remote root login at (Linux)

- Java Virtual Machine Basics (Programming)

- Linux Security Setup Guide (Linux)

- Python extension module Ganglia 3.1.x (Linux)

- High-performance JavaScript reflows and repaints (Programming)

- Effect MongoDB plan cache (Database)

  Upgrade to Node V4 seven reasons
  Add Date : 2018-11-21      
  Two days ago, Node V4 has been officially released. This is after it merged with io.js released the first stable version, many new highlights, added ES6. Has a lot of the ES6 overview, this article we will explain how to use them.

1. Template Strings (String template)

If you've ever tried to create a multi-line JavaScript string, you might be doing:

var message = [
    'The quick brown fox',
    'Jumps over',
    'The lazy dog'
] .join ( '\ N')
This applies only to a small amount of text, more time when the sentence will be very confusing. Therefore, a smart developers came up with a multiline below this is called the hack:

var multiline = require ( 'multiline');
var message = multiline (function () {/ *
    The quick brown fox
    jumps over
    the lazy dog
* /});
Fortunately, ES6 brought us the template string:

var message = `
    The quick brown fox
        jumps over
        the lazy dog
In addition, it gives us a string interpolation:

var name = 'Schroedinger';

// Stop doing this ...
var message = 'Hello' + name + ', how is your cat?';
var message = [ 'Hello', name, ', how is your cat?'] join ( '').;
. Var message = require ( 'util') format ( 'Hello% s, how is your cat?', Name);

// And instead do that ...
var message = `Hello $ {name}, how is your cat`?;
See details on the template string on MDN

2. Classes (class)

ES5 defined class looks a little strange, and it takes some time:

var Pet = function (name) {
    this._name = name;

Pet.prototype.sayHello = function () {
    console.log ( '* scratch *');

Object.defineProperty (Pet.prototype, 'name', {
  get: function () {
    return this._name;

var Cat = function (name) {
    Pet.call (this, name);

require ( 'util') inherits (Cat, Pet).;

Cat.prototype.sayHello = function () {
    Pet.prototype.sayHello.call (this);
    console.log ( 'miaaaauw');
Fortunately, we can now use the Node ES6 syntax:

class Pet {
    constructor (name) {
        this._name = name;
    sayHello () {
        console.log ( '* scratch *');
    get name () {
        return this._name;

class Cat extends Pet {
    constructor (name) {
        super (name);
    sayHello () {
        super.sayHello ();
        console.log ( 'miaaaauw');
Keyword expansion, constructors, call the super class and attributes, is not it great? For more, check out MDN comprehensive guide.

3. Arrow Functions (arrow function)

Often function dynamically bound this will lead to some confusion, people typically use the following ways:

Cat.prototype.notifyListeners = function () {
    var self = this;
    this._listeners.forEach (function (listener) {
        self.notifyListener (listener);

// OR

Cat.prototype.notifyListeners = function () {
    this._listeners.forEach (function (listener) {
        this.notifyListener (listener);
    } .bind (This));
And now, you can use the arrow function:

Cat.prototype.notifyListeners = function () {
    this._listeners.forEach ((listener) => {
        this.notifyListener (listener);
View more detailed information about the function of the arrow

4. Object Literals

By object literals, you can use the following shortcut:

var age = 10, name = 'Petsy', size = 32;

// Instead of this ...
var cat = {
    age: age,
    name: name,
    size: size

// ... Do this ...
var cat = {
In addition, you can also easily add their own function object literals.

5. Promises

No longer need to rely on third-party libraries such as the bluebird or Q, you can use a local Promises. There follows open API:

var p1 = new Promise (function (resolve, reject) {});
var p2 = Promise.resolve (20);
var p3 = Promise.reject (new Error ());
var p4 = Promise.all (p1, p2);
var p5 = Promise.race (p1, p2);

// And obviously
. P1.then (() => {}) catch (() => {});
6. String Methods

There are also some new string method:

// Replace `indexOf ()` in a number of cases
name.startsWith ( 'a')
name.endsWith ( 'c');
name.includes ( 'b');

// Repeat the string three times
name.repeat (3);
Go and tell those kids with Ruby! In addition, treatment of Unicode strings are even better.

7. let and const

Following speculation that the return value of the function call:

var x = 20;
(Function () {
    if (x === 20) {
        var x = 30;
    return x;
} ()); // -> Undefined
. Yep, undefined Replace var with let and you get the expected behaviour:

let x = 20;
(Function () {
    if (x === 20) {
        let x = 30;
    return x;
} ()); // -> 20
Reason: var is a function scope, but let the block scope (as most people expect that). So we can say, let the var variants. You can get more details in the MDN.

Eggs: Node now also supports the const keyword, and it can prevent you give different values for the same reference.

var MY_CONST = 42; // no, no
const MY_CONST = 42; // yes, yes

MY_CONST = 10 // with const, this is no longer possible
to sum up

Node V4 brings ES6 features far more than that, but I hope these seven examples have been able to convince you to update and use the new version.

There are many other features (such as maps / sets ,, symbols and generators, etc.). Make sure you've seen the Node overview of the ES6. Happy upgrading it ~
- Java developers question (Programming)
- Oracle ordinary users show parameter method (Database)
- To execute the cp command prompt type skip folder under CentOS (Linux)
- CentOS 7.0 Automatic installation CD-ROM production Comments (Linux)
- Linux_Logo - output color ANSI Linux distributions logo command-line tool (Linux)
- Ten correct use Redis skills (Database)
- Linux permissions Detailed (Linux)
- MySQL and MariaDB new master from the cluster configuration GTID (Database)
- Kali Linux virtualbox rc = Error 1908 workaround (Linux)
- Remote database using RMAN recovery test (RAC return to single-instance database) (Database)
- Ubuntu to install systems Indicator Sticky Notes 0.4.4 (Linux)
- Build RPM package uses Docker mirror (Linux)
- Use innobackupex full realization of MySQL hot backup (Database)
- Linux script to copy the folder to all folders with the same name (Linux)
- Linux operating system security management skills notes (Linux)
- Inject script commands manually annotated summary (Linux)
- Ubuntu 12.04 / 14.04 users to install software LyX document processing (Linux)
- Linux file permissions bit forced bits and adventure Comments (Linux)
- Spark and Hadoop comparison (Server)
- Python Basics: Search Path (Programming)
  CopyRight 2002-2022 newfreesoft.com, All Rights Reserved.