Class

ES6 引入了 class 语法,提供了关于类构造、继承、静态成员的语法糖。

// define a class 
class Car {
  // constructor method
  constructor(name, year) {
    this.name = name;
    this.year = year;
  }

  // other methods
  run() {
   // ...
  }
}

// create new instance
let myCar1 = new Car("Ford", 2014);

Static

Reference

[1] https://www.w3schools.com/js/js_class_intro.asp

Last updated

Was this helpful?