javascript JS ES6语法

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了javascript JS ES6语法相关的知识,希望对你有一定的参考价值。

{
  "name": "es6",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "build": "babel src -d dist"
  },
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "@babel/cli": "^7.4.4",
    "@babel/core": "^7.4.5",
    "@babel/preset-env": "^7.4.5"
  }
}
// ES6 syntax

//let test = "Hello World";

// ES5 syntax

"use strict";

var test = "Hello World";


//classes
"use strict";

//create class
class User {
  constructor(username, email, password) {
    this.username = username;
    this.email = email;
    this.password = password;
  }

  //create static method
  static countUsers() {
    console.log("There are 50 users");
  }

  register() {
    console.log(this.username + " is registered!");
  }
}

let niweera = new User("Niweera", "w.nipuna@gmail.com", "srilanka");

//niweera.register();

//User.countUsers();

// inheritance 
class Member extends User {
  constructor(username, email, password, memberPackage) {
    super(username, email, password);
    this.package = memberPackage;
  }

  getPackage() {
    console.log(this.username + " is subscribed to " + this.package);
  }
}

let Niweera = new Member(
  "Niweera2",
  "niweera@niweera.gq",
  "srilanka",
  "Premium Package"
);

//Niweera.getPackage();


console.log(Number.isNaN('string'));

以上是关于javascript JS ES6语法的主要内容,如果未能解决你的问题,请参考以下文章

js学习笔记03-ES6语法

如何设置Intellij Idea支持JS ES6语法?

nodejs基础学习1

再学JavaScript ES(6-11)全版本语法大全

js中ES6语法的super到底是啥?

ECMAScript简介以及es6新增语法