Workspace
  • Study Book
  • WEB Network HTTP etc
    • Performance Optimization
    • Performance Optimization
    • HTTP/2 & SPDY
    • WebSocket
    • HTTP Header
    • Cross-Origin Resource Sharing
    • JSON, XML, other format
  • Javascript
    • Promise
    • make API call
    • Web API
    • Common JS
    • AJAX
    • Event DOM and delegation
    • ES6 new features
    • special function
    • function API
  • React
    • class component
    • Example
    • Lifting functions/ state up
    • Hot Loader
    • Testing
    • New Features
    • Hook
    • Simple code
    • Life Cycle
  • CSS
    • Horizontal & Vertical Align
    • GPU Animation
    • transform-function
    • LVHA Pseudo-classes
    • Selector
    • How To CSS
  • HTML
  • Redux
  • NodeJS
    • File System
  • express
    • express questions
    • express mongodb
  • Restful API
  • MongoDB
  • Compare
  • Test
    • Jest
  • Deploy development
  • coding question
  • DevOps
  • Webpack
  • GraphQL
Powered by GitBook
On this page
  • ES6 New Features
  • Class
  • Exports & Imports
  • Spread & Rest Operators ...
  • Destructuring
  • Declaration

Was this helpful?

  1. Javascript

ES6 new features

http://es6-features.org/#Constants

ES6 New Features

  • Let, Const

  • Class

  • Arrow Function

  • Spread Operator and Destructing

  • Modules

  • Promise

  • Symbol

  • Typed Arrays

  • Internationalization & Localization

Class

// ES6
class Human {
    constructor() {
        this.gender = "female";
    }
    
    printGender() {
        console.log(this.gender);
    }
}

class Person extends Human {
    constructor() {
        super();
        this.name = "Harry";
        this.gender = "male";
    }
    
    printMyName() {
        console.log(this.name);
    }
}

const person = new Person();
person.printMyName(); // "Harry"
person.printGender(); // "male"

// ES7
class Human {            
    gender = "female";           
    
    printGender = () => {        
        console.log(this.gender);    
    }
}

class Person extends Human {           
    name = "Harry";        
    gender = "male";         
    
    printMyName = () => {        
        console.log(this.name);    
    }
}
const person = new Person();
person.printMyName(); // "Harry"
person.printGender(); // "male"

Exports & Imports

Default export

Named export

You can choose the name when import

Name is defined by export

import person from "./person.js"

import {person as Person} from "./utility.js"

import * as bundle from "./utility.js"

Spread & Rest Operators ...

Spread

Rest

Used to split up array elements OR object properties

Used to merge a list of function arguments into an array

const newObject = {...oldObject, newProp: 5};

function sortArgs(...) {return args.sort();}

Destructuring

Easily extract array elements or object properties and store them in variables

Array Destructuring

Object Destructuring

[a, b] = ["Hello", "Harry"];

{name} = {name: "Harry", gender: "male"};

Declaration

letDeclares a block-scoped, local variable, optionally initializing it to a value.

constDeclares a block-scoped, read-only named constant.

varDeclares a variable, optionally initializing it to a value.

PreviousEvent DOM and delegationNextspecial function

Last updated 5 years ago

Was this helpful?